Merge pull request #4499 from eugenp/update-all

update to spring 5, fix startup
This commit is contained in:
Loredana Crusoveanu 2018-06-17 21:25:02 +03:00 committed by GitHub
commit de66fb160c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 68 additions and 70 deletions

View File

@ -8,10 +8,10 @@
<packaging>war</packaging>
<parent>
<artifactId>parent-boot-1</artifactId>
<artifactId>parent-boot-2</artifactId>
<groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-1</relativePath>
<relativePath>../parent-boot-2</relativePath>
</parent>
<dependencies>
@ -39,7 +39,6 @@
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>${springretry.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.shell</groupId>
@ -55,11 +54,11 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>${javassist.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
@ -74,6 +73,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- web -->
<dependency>
@ -112,7 +112,6 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@ -139,17 +138,14 @@
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>${ehcache.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
@ -187,6 +183,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
@ -197,22 +194,23 @@
<properties>
<start-class>org.baeldung.sample.App</start-class>
<!-- Spring -->
<org.springframework.version>4.3.4.RELEASE</org.springframework.version>
<org.springframework.security.version>4.2.0.RELEASE</org.springframework.security.version>
<springretry.version>1.1.5.RELEASE</springretry.version>
<org.springframework.version>5.0.6.RELEASE</org.springframework.version>
<org.springframework.security.version>5.0.6.RELEASE</org.springframework.security.version>
<springretry.version>1.2.2.RELEASE</springretry.version>
<org.springframework.shell.version>1.2.0.RELEASE</org.springframework.shell.version>
<!-- persistence -->
<hibernate.version>5.2.5.Final</hibernate.version>
<!-- util -->
<guava.version>19.0</guava.version>
<ehcache.version>3.1.3</ehcache.version>
<easymock.version>3.4</easymock.version>
<guava.version>25.1-jre</guava.version>
<ehcache.version>3.5.2</ehcache.version>
<easymock.version>3.6</easymock.version>
<assertj.version>3.6.1</assertj.version>
<jasperreports.version>6.4.0</jasperreports.version>
<jasperreports.version>6.6.0</jasperreports.version>
<log4j.version>2.8.2</log4j.version>
<javassist.version>3.22.0-GA</javassist.version>
</properties>

View File

@ -4,9 +4,11 @@ import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;
public class AnnotationsBasedApplicationAndServletInitializer extends AbstractDispatcherServletInitializer {
public class AnnotationsBasedApplicationAndServletInitializer //extends AbstractDispatcherServletInitializer
{
@Override
//uncomment to run the multiple contexts example
//@Override
protected WebApplicationContext createRootApplicationContext() {
//If this is not the only class declaring a root context, we return null because it would clash
//with other classes, as there can only be a single root context.
@ -17,19 +19,19 @@ public class AnnotationsBasedApplicationAndServletInitializer extends AbstractDi
return null;
}
@Override
//@Override
protected WebApplicationContext createServletApplicationContext() {
AnnotationConfigWebApplicationContext normalWebAppContext = new AnnotationConfigWebApplicationContext();
normalWebAppContext.register(NormalWebAppConfig.class);
return normalWebAppContext;
}
@Override
//@Override
protected String[] getServletMappings() {
return new String[] { "/api/*" };
}
@Override
//@Override
protected String getServletName() {
return "normal-dispatcher";
}

View File

@ -4,9 +4,10 @@ import org.springframework.web.context.AbstractContextLoaderInitializer;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
public class AnnotationsBasedApplicationInitializer extends AbstractContextLoaderInitializer {
@Override
public class AnnotationsBasedApplicationInitializer //extends AbstractContextLoaderInitializer
{
//uncomment to run the multiple contexts example
// @Override
protected WebApplicationContext createRootApplicationContext() {
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(RootApplicationConfig.class);

View File

@ -12,9 +12,10 @@ import org.springframework.web.context.support.AnnotationConfigWebApplicationCon
import org.springframework.web.context.support.XmlWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
public class ApplicationInitializer implements WebApplicationInitializer {
@Override
public class ApplicationInitializer //implements WebApplicationInitializer
{
//uncomment to run the multiple contexts example
//@Override
public void onStartup(ServletContext servletContext) throws ServletException {
//Here, we can define a root context and register servlets, among other things.
//However, since we've later defined other classes to do the same and they would clash,

View File

@ -5,14 +5,14 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "com.baeldung.contexts.normal" })
public class NormalWebAppConfig extends WebMvcConfigurerAdapter {
public class NormalWebAppConfig implements WebMvcConfigurer {
@Bean
public ViewResolver viewResolver() {

View File

@ -4,27 +4,29 @@ import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;
public class SecureAnnotationsBasedApplicationAndServletInitializer extends AbstractDispatcherServletInitializer {
@Override
public class SecureAnnotationsBasedApplicationAndServletInitializer// extends AbstractDispatcherServletInitializer
{
//uncomment to run the multiple contexts example
//@Override
protected WebApplicationContext createRootApplicationContext() {
return null;
}
@Override
//@Override
protected WebApplicationContext createServletApplicationContext() {
AnnotationConfigWebApplicationContext secureWebAppContext = new AnnotationConfigWebApplicationContext();
secureWebAppContext.register(SecureWebAppConfig.class);
return secureWebAppContext;
}
@Override
//@Override
protected String[] getServletMappings() {
return new String[] { "/s/api/*" };
}
@Override
//@Override
protected String getServletName() {
return "secure-dispatcher";
}

View File

@ -5,14 +5,14 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "com.baeldung.contexts.secure" })
public class SecureWebAppConfig extends WebMvcConfigurerAdapter {
public class SecureWebAppConfig implements WebMvcConfigurer {
@Bean
public ViewResolver viewResolver() {

View File

@ -3,14 +3,12 @@ package com.baeldung.contexts.normal;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.ModelAndView;
import com.baeldung.contexts.services.ApplicationContextUtilService;
import com.baeldung.contexts.services.GreeterService;
@Controller

View File

@ -4,29 +4,27 @@ import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.context.support.GenericWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
public class StudentControllerConfig implements WebApplicationInitializer {
public class StudentControllerConfig //implements WebApplicationInitializer
{
@Override
//uncomment to run the student controller example
//@Override
public void onStartup(ServletContext sc) throws ServletException {
AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
root.register(WebConfig.class);
root.setServletContext(sc);
sc.addListener(new ContextLoaderListener(root));
//Manages the lifecycle of the root application context.
//Conflicts with other root contexts in the application, so we've manually set the parent below.
//sc.addListener(new ContextLoaderListener(root));
GenericWebApplicationContext webApplicationContext = new GenericWebApplicationContext();
webApplicationContext.setParent(root);
DispatcherServlet dv = new DispatcherServlet(webApplicationContext);
DispatcherServlet dv = new DispatcherServlet(root);
ServletRegistration.Dynamic appServlet = sc.addServlet("test-mvc", dv);
appServlet.setLoadOnStartup(1);
appServlet.addMapping("/test/*");

View File

@ -6,13 +6,13 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "org.baeldung.controller.controller", "org.baeldung.controller.config" })
public class WebConfig extends WebMvcConfigurerAdapter {
public class WebConfig implements WebMvcConfigurer {
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();

View File

@ -8,11 +8,11 @@ import java.util.concurrent.TimeUnit;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
@ComponentScan("org.baeldung.core")
public class CoreConfig extends WebMvcConfigurerAdapter {
public class CoreConfig implements WebMvcConfigurer {
public CoreConfig() {
super();

View File

@ -6,13 +6,16 @@ import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.context.support.GenericWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
public class MainWebAppInitializer implements WebApplicationInitializer {
public class MainWebAppInitializer implements WebApplicationInitializer
{
/**
* Register and configure all Servlet container components necessary to power the web application.
@ -26,14 +29,11 @@ public class MainWebAppInitializer implements WebApplicationInitializer {
root.scan("org.baeldung.spring.config");
// root.getEnvironment().setDefaultProfiles("embedded");
//Manages the lifecycle of the root application context.
//Conflicts with other root contexts in the application, so we've manually set the parent below.
//sc.addListener(new ContextLoaderListener(root));
sc.addListener(new ContextLoaderListener(root));
// Handles requests into the application
GenericWebApplicationContext webApplicationContext = new GenericWebApplicationContext();
webApplicationContext.setParent(root);
final ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(webApplicationContext));
DispatcherServlet dv = new DispatcherServlet(root);
final ServletRegistration.Dynamic appServlet = sc.addServlet("mvc",dv);
appServlet.setLoadOnStartup(1);
final Set<String> mappingConflicts = appServlet.addMapping("/");
if (!mappingConflicts.isEmpty()) {

View File

@ -5,13 +5,13 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
@EnableWebMvc
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
public class MvcConfig implements WebMvcConfigurer {
public MvcConfig() {
super();
@ -21,8 +21,6 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(final ViewControllerRegistry registry) {
super.addViewControllers(registry);
registry.addViewController("/sample.html");
}

View File

@ -11,8 +11,8 @@ import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.orm.hibernate5.HibernateTransactionManager;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import com.google.common.base.Preconditions;

View File

@ -38,7 +38,7 @@ public class ScopesConfig {
}
@Bean
@Scope(value = WebApplicationContext.SCOPE_GLOBAL_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
@Scope(value = WebApplicationContext.SCOPE_APPLICATION, proxyMode = ScopedProxyMode.TARGET_CLASS)
public HelloMessageGenerator globalSessionMessage() {
return new HelloMessageGenerator();
}

View File

@ -6,13 +6,13 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@Configuration
@ComponentScan
@EnableWebMvc
public class AttributeAnnotationConfiguration extends WebMvcConfigurerAdapter {
public class AttributeAnnotationConfiguration implements WebMvcConfigurer {
@Bean
public ViewResolver viewResolver() {