commit
bb968a92da
|
@ -8,17 +8,20 @@
|
|||
<packaging>war</packaging>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent-spring-5</artifactId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-spring-5</relativePath>
|
||||
<relativePath>../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
|
@ -33,7 +36,11 @@
|
|||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>${jstl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-jasper</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Jackson -->
|
||||
<dependency>
|
||||
|
@ -55,17 +62,6 @@
|
|||
</dependency>
|
||||
|
||||
<!-- common -->
|
||||
<dependency>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
<version>${commons-fileupload.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.htmlunit</groupId>
|
||||
<artifactId>htmlunit</artifactId>
|
||||
|
@ -106,9 +102,8 @@
|
|||
<version>2.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -134,15 +129,8 @@
|
|||
<version>2.8.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-websocket</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-messaging</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish</groupId>
|
||||
|
@ -296,6 +284,7 @@
|
|||
<poi.version>3.16-beta1</poi.version>
|
||||
|
||||
<javax.el.version>3.0.1-b09</javax.el.version>
|
||||
<start-class>com.baeldung.SpringMVCApplication</start-class>
|
||||
|
||||
</properties>
|
||||
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package com.baeldung;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringMVCApplication extends SpringBootServletInitializer {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringMVCApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -23,15 +23,15 @@ public class LoggingAspect {
|
|||
}
|
||||
};
|
||||
|
||||
@Pointcut("@target(org.springframework.stereotype.Repository)")
|
||||
@Pointcut("within(com.baeldung..*) && execution(* com.baeldung.dao.FooDao.*(..))")
|
||||
public void repositoryMethods() {
|
||||
}
|
||||
|
||||
@Pointcut("@annotation(com.baeldung.aop.annotations.Loggable)")
|
||||
@Pointcut("within(com.baeldung..*) && @annotation(com.baeldung.aop.annotations.Loggable)")
|
||||
public void loggableMethods() {
|
||||
}
|
||||
|
||||
@Pointcut("@args(com.baeldung.aop.annotations.Entity)")
|
||||
@Pointcut("within(com.baeldung..*) && @args(com.baeldung.aop.annotations.Entity)")
|
||||
public void methodsAcceptingEntities() {
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ public class PerformanceAspect {
|
|||
|
||||
private static Logger logger = Logger.getLogger(PerformanceAspect.class.getName());
|
||||
|
||||
@Pointcut("within(@org.springframework.stereotype.Repository *)")
|
||||
@Pointcut("within(com.baeldung..*) && execution(* com.baeldung.dao.FooDao.*(..))")
|
||||
public void repositoryClassMethods() {
|
||||
}
|
||||
|
||||
|
|
|
@ -20,11 +20,11 @@ public class PublishingAspect {
|
|||
this.eventPublisher = eventPublisher;
|
||||
}
|
||||
|
||||
@Pointcut("@target(org.springframework.stereotype.Repository)")
|
||||
@Pointcut("within(com.baeldung..*) && execution(* com.baeldung.dao.FooDao.*(..))")
|
||||
public void repositoryMethods() {
|
||||
}
|
||||
|
||||
@Pointcut("execution(* *..create*(Long,..))")
|
||||
@Pointcut("within(com.baeldung..*) && execution(* com.baeldung.dao.FooDao.create*(Long,..))")
|
||||
public void firstLongParamMethods() {
|
||||
}
|
||||
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
package com.baeldung.config;
|
||||
|
||||
import org.springframework.web.WebApplicationInitializer;
|
||||
import org.springframework.web.context.ContextLoaderListener;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRegistration;
|
||||
|
||||
public class AppInitializer implements WebApplicationInitializer {
|
||||
|
||||
@Override
|
||||
public void onStartup(ServletContext container) throws ServletException {
|
||||
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
||||
|
||||
context.scan("com.baeldung");
|
||||
|
||||
container.addListener(new ContextLoaderListener(context));
|
||||
|
||||
ServletRegistration.Dynamic dispatcher = container.addServlet("mvc", new DispatcherServlet(context));
|
||||
dispatcher.setLoadOnStartup(1);
|
||||
dispatcher.addMapping("/");
|
||||
|
||||
// final MultipartConfigElement multipartConfigElement = new
|
||||
// MultipartConfigElement(TMP_FOLDER, MAX_UPLOAD_SIZE,
|
||||
// MAX_UPLOAD_SIZE * 2, MAX_UPLOAD_SIZE / 2);
|
||||
//
|
||||
// appServlet.setMultipartConfig(multipartConfigElement);
|
||||
}
|
||||
|
||||
}
|
|
@ -3,9 +3,6 @@ package com.baeldung.spring.web.config;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -15,7 +12,6 @@ import org.springframework.context.support.ResourceBundleMessageSource;
|
|||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
||||
import org.springframework.web.servlet.ViewResolver;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
|
||||
|
@ -26,8 +22,9 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
|||
import org.springframework.web.servlet.view.JstlView;
|
||||
import org.springframework.web.util.UrlPathHelper;
|
||||
import org.thymeleaf.spring4.SpringTemplateEngine;
|
||||
import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver;
|
||||
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
|
||||
import org.thymeleaf.templateresolver.ServletContextTemplateResolver;
|
||||
import org.thymeleaf.templateresolver.ITemplateResolver;
|
||||
|
||||
import com.baeldung.excel.ExcelPOIHelper;
|
||||
|
||||
|
@ -35,9 +32,6 @@ import com.baeldung.excel.ExcelPOIHelper;
|
|||
@Configuration
|
||||
@ComponentScan(basePackages = { "com.baeldung.web.controller" })
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Autowired
|
||||
private ServletContext ctx;
|
||||
|
||||
@Override
|
||||
public void addViewControllers(final ViewControllerRegistry registry) {
|
||||
|
@ -64,11 +58,11 @@ public class WebConfig implements WebMvcConfigurer {
|
|||
|
||||
@Bean
|
||||
@Description("Thymeleaf template resolver serving HTML 5")
|
||||
public ServletContextTemplateResolver templateResolver() {
|
||||
final ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(ctx);
|
||||
public ITemplateResolver templateResolver() {
|
||||
final SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
|
||||
templateResolver.setPrefix("/WEB-INF/templates/");
|
||||
templateResolver.setSuffix(".html");
|
||||
templateResolver.setTemplateMode("HTML5");
|
||||
templateResolver.setTemplateMode("HTML");
|
||||
return templateResolver;
|
||||
}
|
||||
|
||||
|
@ -92,15 +86,6 @@ public class WebConfig implements WebMvcConfigurer {
|
|||
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
|
||||
}
|
||||
|
||||
@Bean(name = "multipartResolver")
|
||||
public CommonsMultipartResolver multipartResolver() {
|
||||
|
||||
final CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
|
||||
multipartResolver.setMaxUploadSize(100000);
|
||||
|
||||
return multipartResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extendMessageConverters(final List<HttpMessageConverter<?>> converters) {
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
server.servlet.context-path=/spring-mvc-java
|
||||
spring.servlet.multipart.max-file-size=1MB
|
||||
spring.servlet.multipart.max-request-size=1MB
|
||||
spring.servlet.multipart.enabled=true
|
||||
spring.servlet.multipart.location=${java.io.tmpdir}
|
|
@ -3,15 +3,12 @@ package com.baeldung;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.config.AppInitializer;
|
||||
import com.baeldung.config.TestConfig;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { AppInitializer.class }, loader = AnnotationConfigContextLoader.class)
|
||||
@WebAppConfiguration
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = {TestConfig.class})
|
||||
public class SpringContextIntegrationTest {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -3,15 +3,12 @@ package com.baeldung;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.config.AppInitializer;
|
||||
import com.baeldung.config.TestConfig;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { AppInitializer.class }, loader = AnnotationConfigContextLoader.class)
|
||||
@WebAppConfiguration
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = {TestConfig.class})
|
||||
public class SpringContextTest {
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue