Skip to content

Commit de66fb1

Browse files
authored
Merge pull request eugenp#4499 from eugenp/update-all
update to spring 5, fix startup
2 parents 04d4868 + 67237a1 commit de66fb1

17 files changed

Lines changed: 68 additions & 70 deletions

‎spring-all/pom.xml‎

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
<packaging>war</packaging>
99

1010
<parent>
11-
<artifactId>parent-boot-1</artifactId>
11+
<artifactId>parent-boot-2</artifactId>
1212
<groupId>com.baeldung</groupId>
1313
<version>0.0.1-SNAPSHOT</version>
14-
<relativePath>../parent-boot-1</relativePath>
14+
<relativePath>../parent-boot-2</relativePath>
1515
</parent>
1616

1717
<dependencies>
@@ -39,7 +39,6 @@
3939
<dependency>
4040
<groupId>org.springframework.retry</groupId>
4141
<artifactId>spring-retry</artifactId>
42-
<version>${springretry.version}</version>
4342
</dependency>
4443
<dependency>
4544
<groupId>org.springframework.shell</groupId>
@@ -55,11 +54,11 @@
5554
<dependency>
5655
<groupId>org.hibernate</groupId>
5756
<artifactId>hibernate-core</artifactId>
58-
<version>${hibernate.version}</version>
5957
</dependency>
6058
<dependency>
6159
<groupId>org.javassist</groupId>
6260
<artifactId>javassist</artifactId>
61+
<version>${javassist.version}</version>
6362
</dependency>
6463
<dependency>
6564
<groupId>mysql</groupId>
@@ -74,6 +73,7 @@
7473
<dependency>
7574
<groupId>org.hibernate</groupId>
7675
<artifactId>hibernate-validator</artifactId>
76+
<version>${hibernate.version}</version>
7777
</dependency>
7878
<!-- web -->
7979
<dependency>
@@ -112,7 +112,6 @@
112112
<dependency>
113113
<groupId>org.assertj</groupId>
114114
<artifactId>assertj-core</artifactId>
115-
<version>${assertj.version}</version>
116115
<scope>test</scope>
117116
</dependency>
118117
<dependency>
@@ -139,17 +138,14 @@
139138
<dependency>
140139
<groupId>org.ehcache</groupId>
141140
<artifactId>ehcache</artifactId>
142-
<version>${ehcache.version}</version>
143141
</dependency>
144142
<dependency>
145143
<groupId>org.apache.logging.log4j</groupId>
146144
<artifactId>log4j-api</artifactId>
147-
<version>${log4j.version}</version>
148145
</dependency>
149146
<dependency>
150147
<groupId>org.apache.logging.log4j</groupId>
151148
<artifactId>log4j-core</artifactId>
152-
<version>${log4j.version}</version>
153149
</dependency>
154150
</dependencies>
155151

@@ -187,6 +183,7 @@
187183
<plugin>
188184
<groupId>org.apache.maven.plugins</groupId>
189185
<artifactId>maven-war-plugin</artifactId>
186+
<version>3.2.2</version>
190187
<configuration>
191188
<failOnMissingWebXml>false</failOnMissingWebXml>
192189
</configuration>
@@ -197,22 +194,23 @@
197194
<properties>
198195
<start-class>org.baeldung.sample.App</start-class>
199196
<!-- Spring -->
200-
<org.springframework.version>4.3.4.RELEASE</org.springframework.version>
201-
<org.springframework.security.version>4.2.0.RELEASE</org.springframework.security.version>
202-
<springretry.version>1.1.5.RELEASE</springretry.version>
197+
<org.springframework.version>5.0.6.RELEASE</org.springframework.version>
198+
<org.springframework.security.version>5.0.6.RELEASE</org.springframework.security.version>
199+
<springretry.version>1.2.2.RELEASE</springretry.version>
203200
<org.springframework.shell.version>1.2.0.RELEASE</org.springframework.shell.version>
204201

205202
<!-- persistence -->
206203
<hibernate.version>5.2.5.Final</hibernate.version>
207204

208205
<!-- util -->
209-
<guava.version>19.0</guava.version>
210-
<ehcache.version>3.1.3</ehcache.version>
211-
<easymock.version>3.4</easymock.version>
206+
<guava.version>25.1-jre</guava.version>
207+
<ehcache.version>3.5.2</ehcache.version>
208+
<easymock.version>3.6</easymock.version>
212209
<assertj.version>3.6.1</assertj.version>
213-
<jasperreports.version>6.4.0</jasperreports.version>
210+
<jasperreports.version>6.6.0</jasperreports.version>
214211

215212
<log4j.version>2.8.2</log4j.version>
213+
<javassist.version>3.22.0-GA</javassist.version>
216214

217215
</properties>
218216

‎spring-all/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationAndServletInitializer.java‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
55
import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;
66

7-
public class AnnotationsBasedApplicationAndServletInitializer extends AbstractDispatcherServletInitializer {
7+
public class AnnotationsBasedApplicationAndServletInitializer //extends AbstractDispatcherServletInitializer
8+
{
89

9-
@Override
10+
//uncomment to run the multiple contexts example
11+
//@Override
1012
protected WebApplicationContext createRootApplicationContext() {
1113
//If this is not the only class declaring a root context, we return null because it would clash
1214
//with other classes, as there can only be a single root context.
@@ -17,19 +19,19 @@ protected WebApplicationContext createRootApplicationContext() {
1719
return null;
1820
}
1921

20-
@Override
22+
//@Override
2123
protected WebApplicationContext createServletApplicationContext() {
2224
AnnotationConfigWebApplicationContext normalWebAppContext = new AnnotationConfigWebApplicationContext();
2325
normalWebAppContext.register(NormalWebAppConfig.class);
2426
return normalWebAppContext;
2527
}
2628

27-
@Override
29+
//@Override
2830
protected String[] getServletMappings() {
2931
return new String[] { "/api/*" };
3032
}
3133

32-
@Override
34+
//@Override
3335
protected String getServletName() {
3436
return "normal-dispatcher";
3537
}

‎spring-all/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationInitializer.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
import org.springframework.web.context.WebApplicationContext;
55
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
66

7-
public class AnnotationsBasedApplicationInitializer extends AbstractContextLoaderInitializer {
8-
9-
@Override
7+
public class AnnotationsBasedApplicationInitializer //extends AbstractContextLoaderInitializer
8+
{
9+
//uncomment to run the multiple contexts example
10+
// @Override
1011
protected WebApplicationContext createRootApplicationContext() {
1112
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
1213
rootContext.register(RootApplicationConfig.class);

‎spring-all/src/main/java/com/baeldung/contexts/config/ApplicationInitializer.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
import org.springframework.web.context.support.XmlWebApplicationContext;
1313
import org.springframework.web.servlet.DispatcherServlet;
1414

15-
public class ApplicationInitializer implements WebApplicationInitializer {
16-
17-
@Override
15+
public class ApplicationInitializer //implements WebApplicationInitializer
16+
{
17+
//uncomment to run the multiple contexts example
18+
//@Override
1819
public void onStartup(ServletContext servletContext) throws ServletException {
1920
//Here, we can define a root context and register servlets, among other things.
2021
//However, since we've later defined other classes to do the same and they would clash,

‎spring-all/src/main/java/com/baeldung/contexts/config/NormalWebAppConfig.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
import org.springframework.context.annotation.Configuration;
66
import org.springframework.web.servlet.ViewResolver;
77
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
8-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
8+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
99
import org.springframework.web.servlet.view.InternalResourceViewResolver;
1010
import org.springframework.web.servlet.view.JstlView;
1111

1212
@Configuration
1313
@EnableWebMvc
1414
@ComponentScan(basePackages = { "com.baeldung.contexts.normal" })
15-
public class NormalWebAppConfig extends WebMvcConfigurerAdapter {
15+
public class NormalWebAppConfig implements WebMvcConfigurer {
1616

1717
@Bean
1818
public ViewResolver viewResolver() {

‎spring-all/src/main/java/com/baeldung/contexts/config/SecureAnnotationsBasedApplicationAndServletInitializer.java‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,29 @@
44
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
55
import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;
66

7-
public class SecureAnnotationsBasedApplicationAndServletInitializer extends AbstractDispatcherServletInitializer {
8-
9-
@Override
7+
public class SecureAnnotationsBasedApplicationAndServletInitializer// extends AbstractDispatcherServletInitializer
8+
{
9+
10+
//uncomment to run the multiple contexts example
11+
//@Override
1012
protected WebApplicationContext createRootApplicationContext() {
1113
return null;
1214
}
1315

14-
@Override
16+
//@Override
1517
protected WebApplicationContext createServletApplicationContext() {
1618
AnnotationConfigWebApplicationContext secureWebAppContext = new AnnotationConfigWebApplicationContext();
1719
secureWebAppContext.register(SecureWebAppConfig.class);
1820
return secureWebAppContext;
1921
}
2022

21-
@Override
23+
//@Override
2224
protected String[] getServletMappings() {
2325
return new String[] { "/s/api/*" };
2426
}
2527

2628

27-
@Override
29+
//@Override
2830
protected String getServletName() {
2931
return "secure-dispatcher";
3032
}

‎spring-all/src/main/java/com/baeldung/contexts/config/SecureWebAppConfig.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
import org.springframework.context.annotation.Configuration;
66
import org.springframework.web.servlet.ViewResolver;
77
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
8-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
8+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
99
import org.springframework.web.servlet.view.InternalResourceViewResolver;
1010
import org.springframework.web.servlet.view.JstlView;
1111

1212
@Configuration
1313
@EnableWebMvc
1414
@ComponentScan(basePackages = { "com.baeldung.contexts.secure" })
15-
public class SecureWebAppConfig extends WebMvcConfigurerAdapter {
15+
public class SecureWebAppConfig implements WebMvcConfigurer {
1616

1717
@Bean
1818
public ViewResolver viewResolver() {

‎spring-all/src/main/java/com/baeldung/contexts/normal/HelloWorldController.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
import java.util.Arrays;
44

55
import org.springframework.beans.factory.annotation.Autowired;
6-
import org.springframework.beans.factory.annotation.Qualifier;
76
import org.springframework.stereotype.Controller;
87
import org.springframework.web.bind.annotation.RequestMapping;
98
import org.springframework.web.context.ContextLoader;
109
import org.springframework.web.context.WebApplicationContext;
1110
import org.springframework.web.servlet.ModelAndView;
1211

13-
import com.baeldung.contexts.services.ApplicationContextUtilService;
1412
import com.baeldung.contexts.services.GreeterService;
1513

1614
@Controller

‎spring-all/src/main/java/org/baeldung/controller/config/StudentControllerConfig.java‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,27 @@
44
import javax.servlet.ServletException;
55
import javax.servlet.ServletRegistration;
66

7+
import org.springframework.context.support.GenericApplicationContext;
78
import org.springframework.web.WebApplicationInitializer;
89
import org.springframework.web.context.ContextLoaderListener;
10+
import org.springframework.web.context.WebApplicationContext;
911
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
1012
import org.springframework.web.context.support.GenericWebApplicationContext;
1113
import org.springframework.web.servlet.DispatcherServlet;
1214

13-
public class StudentControllerConfig implements WebApplicationInitializer {
15+
public class StudentControllerConfig //implements WebApplicationInitializer
16+
{
1417

15-
@Override
18+
//uncomment to run the student controller example
19+
//@Override
1620
public void onStartup(ServletContext sc) throws ServletException {
1721
AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
1822
root.register(WebConfig.class);
19-
2023
root.setServletContext(sc);
24+
sc.addListener(new ContextLoaderListener(root));
2125

22-
//Manages the lifecycle of the root application context.
23-
//Conflicts with other root contexts in the application, so we've manually set the parent below.
24-
//sc.addListener(new ContextLoaderListener(root));
25-
26-
GenericWebApplicationContext webApplicationContext = new GenericWebApplicationContext();
27-
webApplicationContext.setParent(root);
28-
DispatcherServlet dv = new DispatcherServlet(webApplicationContext);
29-
26+
DispatcherServlet dv = new DispatcherServlet(root);
27+
3028
ServletRegistration.Dynamic appServlet = sc.addServlet("test-mvc", dv);
3129
appServlet.setLoadOnStartup(1);
3230
appServlet.addMapping("/test/*");

‎spring-all/src/main/java/org/baeldung/controller/config/WebConfig.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
import org.springframework.web.servlet.ViewResolver;
77
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
88
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
9-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
9+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
1010
import org.springframework.web.servlet.view.InternalResourceViewResolver;
1111

1212
@Configuration
1313
@EnableWebMvc
1414
@ComponentScan(basePackages = { "org.baeldung.controller.controller", "org.baeldung.controller.config" })
15-
public class WebConfig extends WebMvcConfigurerAdapter {
15+
public class WebConfig implements WebMvcConfigurer {
1616
@Override
1717
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
1818
configurer.enable();

0 commit comments

Comments
 (0)