1. jsp 파일 웹 페이지로 출력하기
- ServletConfig.java
package works.yermi.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@Configuration
@EnableWebMvc // annotation-driven 대체
@ComponentScan("works.yermi.controller")
@EnableGlobalMethodSecurity(prePostEnabled=true)
public class ServletConfig implements WebMvcConfigurer{
@Override // resources 대체
public void configureViewResolvers(ViewResolverRegistry registry) {
InternalResourceViewResolver resolver = new InternalResourceViewResolver("/WEB-INF/views/", ".jsp");
registry.viewResolver(resolver);
}
@Override // InternalResourceViewResolver 대체
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
}
2. 라이브러리 적용
package works.yermi.config;
// import 생략
@Configuration
@MapperScan("works.yermi.mapper") // 마이바티스 scan
@ComponentScan({"works.yermi.advice", "works.yermi.service", "works.yermi.task"}) // context scan
@EnableAspectJAutoProxy // AOP 관련
@EnableTransactionManagement // 트랜잭션 관련
@EnableScheduling // 스케쥴러 관련
public class RootConfig {
// 기존 코드 생략
@Bean
public DataSourceTransactionManager transactionManager() {
return new DataSourceTransactionManager(dataSource());
}
}