Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions spring-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -74,6 +73,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- web -->
<dependency>
Expand Down Expand Up @@ -112,7 +112,6 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -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>

Expand Down Expand Up @@ -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>
Expand All @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
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.
Expand All @@ -17,19 +19,19 @@ protected WebApplicationContext createRootApplicationContext() {
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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@
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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,27 @@
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/*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
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.
Expand All @@ -26,14 +29,11 @@ public void onStartup(final ServletContext sc) throws ServletException {
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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
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();
Expand All @@ -21,8 +21,6 @@ public MvcConfig() {

@Override
public void addViewControllers(final ViewControllerRegistry registry) {
super.addViewControllers(registry);

registry.addViewController("/sample.html");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
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;
Expand Down
Loading