정보들

java config 설정 의미 (ServletConfig)

인지용 2021. 8. 19. 18:18

 

ServletConfig는

이름에서 처럼 서블릿 즉 , controller 나 어노테이션,  ViewResolver 등을 설정해준다.

 

(ViewResolver)

 

@Bean

public ViewResolver viewResolver() {

InternalResourceViewResolver bean = new InternalResourceViewResolver();

bean.setPrefix("/WEB-INF/views/");

bean.setSuffix(".jsp");

return bean;

}

 

InternalResourceViewResolver는 DispatcherServlet에서 기본적으로 사용하는 뷰리졸버고

setPrefix = url에 밑에 있는

setSuffix = 해당 접미사의 파일을 찾는 것

 

그래서 예) return "member/signup"; 

이렇게 view를 리턴하면 보이진 않지만

/WEB-INF/views/member/signup.jsp 

경로에서 view를 찾아서 클라이언트에 뿌려주는 거임

 

https://windorsky.tistory.com/entry/spring-prefix-suffix-%EC%95%8C%EC%95%84%EB%B3%B4%EA%B8%B0

 

spring prefix / suffix 알아보기

지금 spring 관련 카테고리에 글을 작성하고 있는데요 Spring 설정 중에서 InternalResourceViewResolver를 이용해 View Page를 쉽게 지정을 해보려고 합니다. 우선 InternalResourceViewResolver은 Controller에..

windorsky.tistory.com

 

https://sbarrys.tistory.com/4

 

Web.xml / root-context.xml / servlet-context.xml 차이점

Web.xml - Was 서버가 최초로 구동 될 때, 각종 설정을 정의 - 여러 xml 파일을 인식 할 수 있도록 가리켜 주게 설정 - 설정을 위한 설정파일이라고 봄 sevlet-context .xml - 이름에서 처럼 서블릿 즉 ,controll

sbarrys.tistory.com

 


(resource)

 

@Override

public void addResourceHandlers(ResourceHandlerRegistry registry) {

   registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");

}

 

addResourceHandler = 저 url로 시작하는 리소스 요청이 오면

addResourceLocations = 이 위치에서 해당 리소스를 찾겠다는 뜻

 

https://dailyheumsi.tistory.com/177

 

[스프링 부트 개념과 활용] 웹 MVC 설정 2. 정적 리소스와 웹 JAR

인프런에서 백기선님의 스프링부트 개념과 활용 강의를 듣고, 개인적으로 공부하며 핵심만 정리한 글입니다. 정적 리소스 지원 1) 기본 리소스 위치 기본 리소스 위치는 다음과 같다. classpath:/sta

dailyheumsi.tistory.com

 

 

 

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import com.app.shop.config.DBconfig.ContextDataSource;
import com.app.shop.config.DBconfig.ContextSqlmapper;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages= {"com.app.shop"})
@Import({ContextDataSource.class, ContextSqlmapper.class })
public class ServletConfig implements WebMvcConfigurer{



	@Bean
	public ViewResolver viewResolver() {
		InternalResourceViewResolver bean = new InternalResourceViewResolver();
		bean.setPrefix("/WEB-INF/views/");
		bean.setSuffix(".jsp");
	
		return bean;
	}
	
	
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
	}
	

}