From f5228b6935ad71e1211ae0cdb63138c4fc0622ac Mon Sep 17 00:00:00 2001 From: jmodi Date: Tue, 8 Mar 2016 23:26:05 +0530 Subject: [PATCH 1/6] First controller added --- .../com/baeldung/spring/HelloController.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 spring-mvc-xml/src/main/java/com/baeldung/spring/HelloController.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/HelloController.java b/spring-mvc-xml/src/main/java/com/baeldung/spring/HelloController.java new file mode 100644 index 0000000000..97d7ceb22c --- /dev/null +++ b/spring-mvc-xml/src/main/java/com/baeldung/spring/HelloController.java @@ -0,0 +1,17 @@ +package com.baeldung.spring; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.mvc.AbstractController; + +public class HelloController extends AbstractController { + @Override + protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { + ModelAndView model = new ModelAndView("helloworld"); + model.addObject("msg", "!! Welcome to baeldung's Spring Handler Mappings Guide.
This is using SimpleUrlHandlerMapping."); + + return model; + } +} From 453b6f4b5d5f8fe1b15394abdca466eeb4392e7e Mon Sep 17 00:00:00 2001 From: jmodi Date: Sat, 12 Mar 2016 14:27:31 +0530 Subject: [PATCH 2/6] First complete commit for spring-handler-mapping --- spring-mvc-xml/.classpath | 43 ++++++++++++---- spring-mvc-xml/.project | 4 +- .../.settings/org.eclipse.jdt.core.prefs | 5 ++ .../org.eclipse.wst.common.component | 1 + .../{ => controller}/HelloController.java | 2 +- .../controller/HelloGuestController.java | 17 +++++++ .../controller/HelloWorldController.java | 17 +++++++ .../spring/controller/WelcomeController.java | 18 +++++++ .../src/main/webapp/WEB-INF/mvc-servlet.xml | 51 +++++++++++++++++++ .../src/main/webapp/WEB-INF/view/hello.jsp | 15 ++++++ .../main/webapp/WEB-INF/view/helloworld.jsp | 15 ++++++ .../src/main/webapp/WEB-INF/view/welcome.jsp | 15 ++++++ spring-mvc-xml/src/main/webapp/index.jsp | 3 ++ .../src/main/webapp/spring-handler-index.jsp | 26 ++++++++++ 14 files changed, 220 insertions(+), 12 deletions(-) rename spring-mvc-xml/src/main/java/com/baeldung/spring/{ => controller}/HelloController.java (94%) create mode 100644 spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloGuestController.java create mode 100644 spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloWorldController.java create mode 100644 spring-mvc-xml/src/main/java/com/baeldung/spring/controller/WelcomeController.java create mode 100644 spring-mvc-xml/src/main/webapp/WEB-INF/view/hello.jsp create mode 100644 spring-mvc-xml/src/main/webapp/WEB-INF/view/helloworld.jsp create mode 100644 spring-mvc-xml/src/main/webapp/WEB-INF/view/welcome.jsp create mode 100644 spring-mvc-xml/src/main/webapp/spring-handler-index.jsp diff --git a/spring-mvc-xml/.classpath b/spring-mvc-xml/.classpath index 6b533711d3..24a63f3df7 100644 --- a/spring-mvc-xml/.classpath +++ b/spring-mvc-xml/.classpath @@ -1,12 +1,11 @@ - + - - + @@ -17,7 +16,38 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -28,10 +58,5 @@ - - - - - diff --git a/spring-mvc-xml/.project b/spring-mvc-xml/.project index de41bcaace..e0267781eb 100644 --- a/spring-mvc-xml/.project +++ b/spring-mvc-xml/.project @@ -1,7 +1,7 @@ spring-mvc-xml - + NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. @@ -32,11 +32,11 @@ + org.eclipse.m2e.core.maven2Nature org.springframework.ide.eclipse.core.springnature org.eclipse.jem.workbench.JavaEMFNature org.eclipse.wst.common.modulecore.ModuleCoreNature org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature org.eclipse.wst.common.project.facet.core.nature org.eclipse.wst.jsdt.core.jsNature diff --git a/spring-mvc-xml/.settings/org.eclipse.jdt.core.prefs b/spring-mvc-xml/.settings/org.eclipse.jdt.core.prefs index 5ff04b9f96..c57289fc09 100644 --- a/spring-mvc-xml/.settings/org.eclipse.jdt.core.prefs +++ b/spring-mvc-xml/.settings/org.eclipse.jdt.core.prefs @@ -5,8 +5,13 @@ org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annota org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.autoboxing=ignore diff --git a/spring-mvc-xml/.settings/org.eclipse.wst.common.component b/spring-mvc-xml/.settings/org.eclipse.wst.common.component index fc995759ac..e54e3acac9 100644 --- a/spring-mvc-xml/.settings/org.eclipse.wst.common.component +++ b/spring-mvc-xml/.settings/org.eclipse.wst.common.component @@ -4,6 +4,7 @@ + diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/HelloController.java b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloController.java similarity index 94% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/HelloController.java rename to spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloController.java index 97d7ceb22c..766aa6670a 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/spring/HelloController.java +++ b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloController.java @@ -1,4 +1,4 @@ -package com.baeldung.spring; +package com.baeldung.spring.controller; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloGuestController.java b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloGuestController.java new file mode 100644 index 0000000000..5c19dc2295 --- /dev/null +++ b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloGuestController.java @@ -0,0 +1,17 @@ +package com.baeldung.spring.controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.mvc.AbstractController; + +public class HelloGuestController extends AbstractController { + @Override + protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { + ModelAndView model = new ModelAndView("helloworld"); + model.addObject("msg", "!! Welcome to baeldung's Spring Handler Mappings Guide.
This is using ControllerClassNameHandlerMapping."); + + return model; + } +} diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloWorldController.java b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloWorldController.java new file mode 100644 index 0000000000..0659b3815d --- /dev/null +++ b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloWorldController.java @@ -0,0 +1,17 @@ +package com.baeldung.spring.controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.mvc.AbstractController; + +public class HelloWorldController extends AbstractController { + @Override + protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { + ModelAndView model = new ModelAndView("helloworld"); + model.addObject("msg", "!! Welcome to baeldung's Spring Handler Mappings Guide.
This is using BeanNameUrlHandlerMapping."); + + return model; + } +} diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/WelcomeController.java b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/WelcomeController.java new file mode 100644 index 0000000000..e3c8bc5a25 --- /dev/null +++ b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/WelcomeController.java @@ -0,0 +1,18 @@ +package com.baeldung.spring.controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.mvc.AbstractController; + +public class WelcomeController extends AbstractController { + @Override + protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { + + ModelAndView model = new ModelAndView("welcome"); + model.addObject("msg", " baeldung's Spring Handler Mappings Guide.
This is using SimpleUrlHandlerMapping."); + + return model; + } +} \ No newline at end of file diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-mvc-xml/src/main/webapp/WEB-INF/mvc-servlet.xml index 4ba9642448..400c7b5e86 100644 --- a/spring-mvc-xml/src/main/webapp/WEB-INF/mvc-servlet.xml +++ b/spring-mvc-xml/src/main/webapp/WEB-INF/mvc-servlet.xml @@ -3,4 +3,55 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd" > + + + + + + + + + + + + + + + + + + + welcomeController + welcomeController + helloController + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/hello.jsp b/spring-mvc-xml/src/main/webapp/WEB-INF/view/hello.jsp new file mode 100644 index 0000000000..2acdae9b0f --- /dev/null +++ b/spring-mvc-xml/src/main/webapp/WEB-INF/view/hello.jsp @@ -0,0 +1,15 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Hello World + + +

Hello ${msg}

+
+

+ Go to spring handler mappings homepage + + \ No newline at end of file diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/helloworld.jsp b/spring-mvc-xml/src/main/webapp/WEB-INF/view/helloworld.jsp new file mode 100644 index 0000000000..2eeabbe0ac --- /dev/null +++ b/spring-mvc-xml/src/main/webapp/WEB-INF/view/helloworld.jsp @@ -0,0 +1,15 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Hello World + + +

Hello World ${msg}

+
+

+ Go to spring handler mappings homepage + + \ No newline at end of file diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/welcome.jsp b/spring-mvc-xml/src/main/webapp/WEB-INF/view/welcome.jsp new file mode 100644 index 0000000000..348ca652ff --- /dev/null +++ b/spring-mvc-xml/src/main/webapp/WEB-INF/view/welcome.jsp @@ -0,0 +1,15 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Welcome Page + + +

Welcome to ${msg}

+
+

+ Go to spring handler mappings homepage + + \ No newline at end of file diff --git a/spring-mvc-xml/src/main/webapp/index.jsp b/spring-mvc-xml/src/main/webapp/index.jsp index 1ecfcec9d7..ef9279f6e5 100644 --- a/spring-mvc-xml/src/main/webapp/index.jsp +++ b/spring-mvc-xml/src/main/webapp/index.jsp @@ -13,6 +13,9 @@

+ \ No newline at end of file diff --git a/spring-mvc-xml/src/main/webapp/spring-handler-index.jsp b/spring-mvc-xml/src/main/webapp/spring-handler-index.jsp new file mode 100644 index 0000000000..d915b344cb --- /dev/null +++ b/spring-mvc-xml/src/main/webapp/spring-handler-index.jsp @@ -0,0 +1,26 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Welcome + + +

Welcome to Spring Handler Mapping Example

+

Click below link to understand each mentioned Handler Mapping: +

+

+ 1. BeanNameUrlHandlerMapping + - Mapping by bean name
+

+ 2. SimpleUrlHandlerMapping +
+

+ 3. ControllerClassNameHandlerMapping + - Mapping by controller name
+

+ Go to spring handler mappings + homepage + + \ No newline at end of file From c1566e58518a8adcf3d2814d17618268def45820 Mon Sep 17 00:00:00 2001 From: Thai Nguyen Date: Thu, 31 Mar 2016 20:02:10 +0700 Subject: [PATCH 3/6] remove connection pooling --- jooq-spring/pom.xml | 6 ------ .../jooq/introduction/PersistenceContext.java | 13 +++++-------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/jooq-spring/pom.xml b/jooq-spring/pom.xml index 5465b86736..76198c4993 100644 --- a/jooq-spring/pom.xml +++ b/jooq-spring/pom.xml @@ -8,7 +8,6 @@ 3.7.3 1.4.191 - 2.4.4 4.2.5.RELEASE 1.7.18 1.1.3 @@ -29,11 +28,6 @@ h2 ${com.h2database.version} - - com.zaxxer - HikariCP - ${com.zaxxer.HikariCP.version} - diff --git a/jooq-spring/src/test/java/com/baeldung/jooq/introduction/PersistenceContext.java b/jooq-spring/src/test/java/com/baeldung/jooq/introduction/PersistenceContext.java index 4bcf3a527e..ee34c00679 100644 --- a/jooq-spring/src/test/java/com/baeldung/jooq/introduction/PersistenceContext.java +++ b/jooq-spring/src/test/java/com/baeldung/jooq/introduction/PersistenceContext.java @@ -1,14 +1,12 @@ package com.baeldung.jooq.introduction; import javax.sql.DataSource; -import com.zaxxer.hikari.HikariDataSource; - +import org.h2.jdbcx.JdbcDataSource; import org.jooq.SQLDialect; import org.jooq.impl.DataSourceConnectionProvider; import org.jooq.impl.DefaultConfiguration; import org.jooq.impl.DefaultDSLContext; import org.jooq.impl.DefaultExecuteListenerProvider; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -29,11 +27,10 @@ public class PersistenceContext { @Bean public DataSource dataSource() { - HikariDataSource dataSource = new HikariDataSource(); - - dataSource.setDriverClassName(environment.getRequiredProperty("db.driver")); - dataSource.setJdbcUrl(environment.getRequiredProperty("db.url")); - dataSource.setUsername(environment.getRequiredProperty("db.username")); + JdbcDataSource dataSource = new JdbcDataSource(); + + dataSource.setUrl(environment.getRequiredProperty("db.url")); + dataSource.setUser(environment.getRequiredProperty("db.username")); dataSource.setPassword(environment.getRequiredProperty("db.password")); return dataSource; From 2f9524ae8e08e5ce7974f2ee3cd3a2b4d62b2144 Mon Sep 17 00:00:00 2001 From: David Morley Date: Sun, 3 Apr 2016 04:59:27 -0500 Subject: [PATCH 4/6] Clean up jOOQ examples --- .../baeldung/jooq/introduction/QueryTest.java | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/jooq-spring/src/test/java/com/baeldung/jooq/introduction/QueryTest.java b/jooq-spring/src/test/java/com/baeldung/jooq/introduction/QueryTest.java index 34be23bf2a..bc12dff5a0 100644 --- a/jooq-spring/src/test/java/com/baeldung/jooq/introduction/QueryTest.java +++ b/jooq-spring/src/test/java/com/baeldung/jooq/introduction/QueryTest.java @@ -1,31 +1,29 @@ package com.baeldung.jooq.introduction; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.junit.runner.RunWith; - +import com.baeldung.jooq.introduction.db.public_.tables.Author; +import com.baeldung.jooq.introduction.db.public_.tables.AuthorBook; +import com.baeldung.jooq.introduction.db.public_.tables.Book; import org.jooq.DSLContext; import org.jooq.Record3; import org.jooq.Result; import org.jooq.impl.DSL; - +import org.junit.Test; +import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; -import com.baeldung.jooq.introduction.db.public_.tables.Author; -import com.baeldung.jooq.introduction.db.public_.tables.AuthorBook; -import com.baeldung.jooq.introduction.db.public_.tables.Book; +import static org.junit.Assert.assertEquals; @ContextConfiguration(classes = PersistenceContext.class) @Transactional(transactionManager = "transactionManager") @RunWith(SpringJUnit4ClassRunner.class) public class QueryTest { + @Autowired - private DSLContext create; + private DSLContext dsl; Author author = Author.AUTHOR; Book book = Book.BOOK; @@ -33,10 +31,10 @@ public class QueryTest { @Test public void givenValidData_whenInserting_thenSucceed() { - create.insertInto(author).set(author.ID, 4).set(author.FIRST_NAME, "Herbert").set(author.LAST_NAME, "Schildt").execute(); - create.insertInto(book).set(book.ID, 4).set(book.TITLE, "A Beginner's Guide").execute(); - create.insertInto(authorBook).set(authorBook.AUTHOR_ID, 4).set(authorBook.BOOK_ID, 4).execute(); - Result> result = create.select(author.ID, author.LAST_NAME, DSL.count()).from(author).join(authorBook).on(author.ID.equal(authorBook.AUTHOR_ID)).join(book).on(authorBook.BOOK_ID.equal(book.ID)) + dsl.insertInto(author).set(author.ID, 4).set(author.FIRST_NAME, "Herbert").set(author.LAST_NAME, "Schildt").execute(); + dsl.insertInto(book).set(book.ID, 4).set(book.TITLE, "A Beginner's Guide").execute(); + dsl.insertInto(authorBook).set(authorBook.AUTHOR_ID, 4).set(authorBook.BOOK_ID, 4).execute(); + Result> result = dsl.select(author.ID, author.LAST_NAME, DSL.count()).from(author).join(authorBook).on(author.ID.equal(authorBook.AUTHOR_ID)).join(book).on(authorBook.BOOK_ID.equal(book.ID)) .groupBy(author.LAST_NAME).fetch(); assertEquals(3, result.size()); @@ -48,15 +46,15 @@ public class QueryTest { @Test(expected = DataAccessException.class) public void givenInvalidData_whenInserting_thenFail() { - create.insertInto(authorBook).set(authorBook.AUTHOR_ID, 4).set(authorBook.BOOK_ID, 5).execute(); + dsl.insertInto(authorBook).set(authorBook.AUTHOR_ID, 4).set(authorBook.BOOK_ID, 5).execute(); } @Test public void givenValidData_whenUpdating_thenSucceed() { - create.update(author).set(author.LAST_NAME, "Baeldung").where(author.ID.equal(3)).execute(); - create.update(book).set(book.TITLE, "Building your REST API with Spring").where(book.ID.equal(3)).execute(); - create.insertInto(authorBook).set(authorBook.AUTHOR_ID, 3).set(authorBook.BOOK_ID, 3).execute(); - Result> result = create.select(author.ID, author.LAST_NAME, book.TITLE).from(author).join(authorBook).on(author.ID.equal(authorBook.AUTHOR_ID)).join(book).on(authorBook.BOOK_ID.equal(book.ID)).where(author.ID.equal(3)) + dsl.update(author).set(author.LAST_NAME, "Baeldung").where(author.ID.equal(3)).execute(); + dsl.update(book).set(book.TITLE, "Building your REST API with Spring").where(book.ID.equal(3)).execute(); + dsl.insertInto(authorBook).set(authorBook.AUTHOR_ID, 3).set(authorBook.BOOK_ID, 3).execute(); + Result> result = dsl.select(author.ID, author.LAST_NAME, book.TITLE).from(author).join(authorBook).on(author.ID.equal(authorBook.AUTHOR_ID)).join(book).on(authorBook.BOOK_ID.equal(book.ID)).where(author.ID.equal(3)) .fetch(); assertEquals(1, result.size()); @@ -67,13 +65,13 @@ public class QueryTest { @Test(expected = DataAccessException.class) public void givenInvalidData_whenUpdating_thenFail() { - create.update(authorBook).set(authorBook.AUTHOR_ID, 4).set(authorBook.BOOK_ID, 5).execute(); + dsl.update(authorBook).set(authorBook.AUTHOR_ID, 4).set(authorBook.BOOK_ID, 5).execute(); } @Test public void givenValidData_whenDeleting_thenSucceed() { - create.delete(author).where(author.ID.lt(3)).execute(); - Result> result = create.select(author.ID, author.FIRST_NAME, author.LAST_NAME).from(author).fetch(); + dsl.delete(author).where(author.ID.lt(3)).execute(); + Result> result = dsl.select(author.ID, author.FIRST_NAME, author.LAST_NAME).from(author).fetch(); assertEquals(1, result.size()); assertEquals("Bryan", result.getValue(0, author.FIRST_NAME)); @@ -82,6 +80,6 @@ public class QueryTest { @Test(expected = DataAccessException.class) public void givenInvalidData_whenDeleting_thenFail() { - create.delete(book).where(book.ID.equal(1)).execute(); + dsl.delete(book).where(book.ID.equal(1)).execute(); } } \ No newline at end of file From 9b262c9381eca09f00c1e48abad52be33275e11c Mon Sep 17 00:00:00 2001 From: DOHA Date: Sun, 3 Apr 2016 19:13:25 +0200 Subject: [PATCH 5/6] add java configuration --- .../baeldung/spring/SecSecurityConfig.java | 51 +++++++++++++++- .../src/main/webapp/WEB-INF/web.xml | 9 ++- ...SimpleUrlAuthenticationSuccessHandler.java | 2 +- .../baeldung/spring/SecSecurityConfig.java | 58 ++++++++++++++++++- .../src/main/webapp/WEB-INF/web.xml | 13 ++--- .../config/parent/SecurityConfig.java | 31 +++++++++- 6 files changed, 142 insertions(+), 22 deletions(-) diff --git a/spring-security-mvc-login/src/main/java/org/baeldung/spring/SecSecurityConfig.java b/spring-security-mvc-login/src/main/java/org/baeldung/spring/SecSecurityConfig.java index 4da114c78b..08cb09384b 100644 --- a/spring-security-mvc-login/src/main/java/org/baeldung/spring/SecSecurityConfig.java +++ b/spring-security-mvc-login/src/main/java/org/baeldung/spring/SecSecurityConfig.java @@ -1,14 +1,59 @@ package org.baeldung.spring; +import org.baeldung.security.CustomLogoutSuccessHandler; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; @Configuration -@ImportResource({ "classpath:webSecurityConfig.xml" }) -public class SecSecurityConfig { +// @ImportResource({ "classpath:webSecurityConfig.xml" }) +@EnableWebSecurity +public class SecSecurityConfig extends WebSecurityConfigurerAdapter { public SecSecurityConfig() { super(); } + @Override + protected void configure(final AuthenticationManagerBuilder auth) throws Exception { + // @formatter:off + auth.inMemoryAuthentication() + .withUser("user1").password("user1Pass").roles("USER") + .and() + .withUser("user2").password("user2Pass").roles("USER"); + // @formatter:on + } + + @Override + protected void configure(final HttpSecurity http) throws Exception { + // @formatter:off + http + .csrf().disable() + .authorizeRequests() + .antMatchers("/anonymous*").anonymous() + .antMatchers("/login*").permitAll() + .anyRequest().authenticated() + .and() + .formLogin() + .loginPage("/login.html") + .loginProcessingUrl("/perform_login") + .defaultSuccessUrl("/homepage.html",true) + .failureUrl("/login.html?error=true") + .and() + .logout() + .logoutUrl("/perform_logout") + .deleteCookies("JSESSIONID") + .logoutSuccessHandler(logoutSuccessHandler()); + // @formatter:on + } + + @Bean + public LogoutSuccessHandler logoutSuccessHandler() { + return new CustomLogoutSuccessHandler(); + } + } diff --git a/spring-security-mvc-login/src/main/webapp/WEB-INF/web.xml b/spring-security-mvc-login/src/main/webapp/WEB-INF/web.xml index f13ae48c7e..0a0a340995 100644 --- a/spring-security-mvc-login/src/main/webapp/WEB-INF/web.xml +++ b/spring-security-mvc-login/src/main/webapp/WEB-INF/web.xml @@ -1,9 +1,8 @@ - + Spring MVC Application diff --git a/spring-security-mvc-session/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java b/spring-security-mvc-session/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java index 19f1ca76a6..19f49ea59d 100644 --- a/spring-security-mvc-session/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java +++ b/spring-security-mvc-session/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java @@ -21,7 +21,7 @@ public class MySimpleUrlAuthenticationSuccessHandler implements AuthenticationSu private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); - protected MySimpleUrlAuthenticationSuccessHandler() { + public MySimpleUrlAuthenticationSuccessHandler() { super(); } diff --git a/spring-security-mvc-session/src/main/java/org/baeldung/spring/SecSecurityConfig.java b/spring-security-mvc-session/src/main/java/org/baeldung/spring/SecSecurityConfig.java index 4da114c78b..c62b795e01 100644 --- a/spring-security-mvc-session/src/main/java/org/baeldung/spring/SecSecurityConfig.java +++ b/spring-security-mvc-session/src/main/java/org/baeldung/spring/SecSecurityConfig.java @@ -1,14 +1,66 @@ package org.baeldung.spring; +import org.baeldung.security.MySimpleUrlAuthenticationSuccessHandler; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.web.authentication.AuthenticationSuccessHandler; +import org.springframework.security.web.session.HttpSessionEventPublisher; @Configuration -@ImportResource({ "classpath:webSecurityConfig.xml" }) -public class SecSecurityConfig { +// @ImportResource({ "classpath:webSecurityConfig.xml" }) +@EnableWebSecurity +public class SecSecurityConfig extends WebSecurityConfigurerAdapter { public SecSecurityConfig() { super(); } + @Override + protected void configure(final AuthenticationManagerBuilder auth) throws Exception { + // @formatter:off + auth.inMemoryAuthentication() + .withUser("user1").password("user1Pass").roles("USER") + .and() + .withUser("admin1").password("admin1Pass").roles("ADMIN"); + // @formatter:on + } + + @Override + protected void configure(final HttpSecurity http) throws Exception { + // @formatter:off + http + .csrf().disable() + .authorizeRequests() + .antMatchers("/anonymous*").anonymous() + .antMatchers("/login*").permitAll() + .anyRequest().authenticated() + .and() + .formLogin() + .loginPage("/login.html") + .loginProcessingUrl("/login") + .successHandler(successHandler()) + .failureUrl("/login.html?error=true") + .and() + .logout().deleteCookies("JSESSIONID") + .and() + .rememberMe().key("uniqueAndSecret").tokenValiditySeconds(86400) + .and() + .sessionManagement().invalidSessionUrl("/invalidSession.html").maximumSessions(2).expiredUrl("/sessionExpired.html"); + + // @formatter:on + } + + private AuthenticationSuccessHandler successHandler() { + return new MySimpleUrlAuthenticationSuccessHandler(); + } + + @Bean + public HttpSessionEventPublisher httpSessionEventPublisher() { + return new HttpSessionEventPublisher(); + } + } diff --git a/spring-security-mvc-session/src/main/webapp/WEB-INF/web.xml b/spring-security-mvc-session/src/main/webapp/WEB-INF/web.xml index 45b49b2a91..57826fadac 100644 --- a/spring-security-mvc-session/src/main/webapp/WEB-INF/web.xml +++ b/spring-security-mvc-session/src/main/webapp/WEB-INF/web.xml @@ -1,9 +1,8 @@ - + Spring MVC Session Application @@ -13,9 +12,9 @@ org.baeldung.web.SessionListenerWithMetrics - + diff --git a/spring-security-rest-custom/src/main/java/org/baeldung/config/parent/SecurityConfig.java b/spring-security-rest-custom/src/main/java/org/baeldung/config/parent/SecurityConfig.java index ee9b0868e7..67d9abbae5 100644 --- a/spring-security-rest-custom/src/main/java/org/baeldung/config/parent/SecurityConfig.java +++ b/spring-security-rest-custom/src/main/java/org/baeldung/config/parent/SecurityConfig.java @@ -1,16 +1,41 @@ package org.baeldung.config.parent; +import org.baeldung.security.CustomAuthenticationProvider; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; @Configuration -@ImportResource({ "classpath:webSecurityConfig.xml" }) +// @ImportResource({ "classpath:webSecurityConfig.xml" }) +@EnableWebSecurity @ComponentScan("org.baeldung.security") -public class SecurityConfig { +public class SecurityConfig extends WebSecurityConfigurerAdapter { + + @Autowired + private CustomAuthenticationProvider authProvider; public SecurityConfig() { super(); } + @Override + protected void configure(final AuthenticationManagerBuilder auth) throws Exception { + auth.authenticationProvider(authProvider); + } + + @Override + protected void configure(final HttpSecurity http) throws Exception { + // @formatter:off + http + .authorizeRequests().anyRequest().authenticated() + .and() + .httpBasic(); + // @formatter:on + } + + } From 68e20baeede810aa6878d4d1648682727be1f619 Mon Sep 17 00:00:00 2001 From: David Morley Date: Sun, 3 Apr 2016 15:28:16 -0500 Subject: [PATCH 6/6] Clean up Spring Handler Mapping examples --- spring-mvc-xml/.classpath | 62 ------------ ...e.wst.jsdt.core.javascriptValidator.launch | 7 -- spring-mvc-xml/.project | 43 --------- spring-mvc-xml/.settings/.jsdtscope | 12 --- .../.settings/org.eclipse.jdt.core.prefs | 96 ------------------- .../.settings/org.eclipse.jdt.ui.prefs | 55 ----------- .../.settings/org.eclipse.m2e.core.prefs | 4 - .../.settings/org.eclipse.m2e.wtp.prefs | 2 - .../org.eclipse.wst.common.component | 11 --- ....eclipse.wst.common.project.facet.core.xml | 6 -- ...rg.eclipse.wst.jsdt.ui.superType.container | 1 - .../org.eclipse.wst.jsdt.ui.superType.name | 1 - .../org.eclipse.wst.validation.prefs | 15 --- .../org.eclipse.wst.ws.service.policy.prefs | 2 - spring-mvc-xml/.springBeans | 14 --- .../spring/controller/HelloController.java | 4 +- .../controller/HelloGuestController.java | 3 +- .../controller/HelloWorldController.java | 3 +- .../spring/controller/WelcomeController.java | 3 +- .../src/main/webapp/WEB-INF/mvc-servlet.xml | 84 ++++++++-------- spring-mvc-xml/src/main/webapp/index.jsp | 4 +- .../src/main/webapp/spring-handler-index.jsp | 30 +++--- 22 files changed, 63 insertions(+), 399 deletions(-) delete mode 100644 spring-mvc-xml/.classpath delete mode 100644 spring-mvc-xml/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch delete mode 100644 spring-mvc-xml/.project delete mode 100644 spring-mvc-xml/.settings/.jsdtscope delete mode 100644 spring-mvc-xml/.settings/org.eclipse.jdt.core.prefs delete mode 100644 spring-mvc-xml/.settings/org.eclipse.jdt.ui.prefs delete mode 100644 spring-mvc-xml/.settings/org.eclipse.m2e.core.prefs delete mode 100644 spring-mvc-xml/.settings/org.eclipse.m2e.wtp.prefs delete mode 100644 spring-mvc-xml/.settings/org.eclipse.wst.common.component delete mode 100644 spring-mvc-xml/.settings/org.eclipse.wst.common.project.facet.core.xml delete mode 100644 spring-mvc-xml/.settings/org.eclipse.wst.jsdt.ui.superType.container delete mode 100644 spring-mvc-xml/.settings/org.eclipse.wst.jsdt.ui.superType.name delete mode 100644 spring-mvc-xml/.settings/org.eclipse.wst.validation.prefs delete mode 100644 spring-mvc-xml/.settings/org.eclipse.wst.ws.service.policy.prefs delete mode 100644 spring-mvc-xml/.springBeans diff --git a/spring-mvc-xml/.classpath b/spring-mvc-xml/.classpath deleted file mode 100644 index 24a63f3df7..0000000000 --- a/spring-mvc-xml/.classpath +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-mvc-xml/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch b/spring-mvc-xml/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch deleted file mode 100644 index 627021fb96..0000000000 --- a/spring-mvc-xml/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/spring-mvc-xml/.project b/spring-mvc-xml/.project deleted file mode 100644 index e0267781eb..0000000000 --- a/spring-mvc-xml/.project +++ /dev/null @@ -1,43 +0,0 @@ - - - spring-mvc-xml - NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.wst.common.project.facet.core.builder - - - - - org.eclipse.wst.validation.validationbuilder - - - - - org.springframework.ide.eclipse.core.springbuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.m2e.core.maven2Nature - org.springframework.ide.eclipse.core.springnature - org.eclipse.jem.workbench.JavaEMFNature - org.eclipse.wst.common.modulecore.ModuleCoreNature - org.eclipse.jdt.core.javanature - org.eclipse.wst.common.project.facet.core.nature - org.eclipse.wst.jsdt.core.jsNature - - diff --git a/spring-mvc-xml/.settings/.jsdtscope b/spring-mvc-xml/.settings/.jsdtscope deleted file mode 100644 index b46b9207a8..0000000000 --- a/spring-mvc-xml/.settings/.jsdtscope +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-mvc-xml/.settings/org.eclipse.jdt.core.prefs b/spring-mvc-xml/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index c57289fc09..0000000000 --- a/spring-mvc-xml/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,96 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore -org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull -org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault -org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable -org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.autoboxing=ignore -org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning -org.eclipse.jdt.core.compiler.problem.deadCode=warning -org.eclipse.jdt.core.compiler.problem.deprecation=warning -org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled -org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled -org.eclipse.jdt.core.compiler.problem.discouragedReference=warning -org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore -org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore -org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled -org.eclipse.jdt.core.compiler.problem.fieldHiding=error -org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning -org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning -org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled -org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning -org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore -org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore -org.eclipse.jdt.core.compiler.problem.localVariableHiding=error -org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning -org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore -org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled -org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled -org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning -org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore -org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning -org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning -org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore -org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error -org.eclipse.jdt.core.compiler.problem.nullReference=warning -org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error -org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning -org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning -org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore -org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore -org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore -org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore -org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning -org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning -org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore -org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore -org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore -org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore -org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore -org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled -org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning -org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled -org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled -org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore -org.eclipse.jdt.core.compiler.problem.typeParameterHiding=error -org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled -org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning -org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning -org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore -org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning -org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore -org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore -org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled -org.eclipse.jdt.core.compiler.problem.unusedImport=warning -org.eclipse.jdt.core.compiler.problem.unusedLabel=warning -org.eclipse.jdt.core.compiler.problem.unusedLocal=warning -org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore -org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore -org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled -org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning -org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning -org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.8 diff --git a/spring-mvc-xml/.settings/org.eclipse.jdt.ui.prefs b/spring-mvc-xml/.settings/org.eclipse.jdt.ui.prefs deleted file mode 100644 index 471e9b0d81..0000000000 --- a/spring-mvc-xml/.settings/org.eclipse.jdt.ui.prefs +++ /dev/null @@ -1,55 +0,0 @@ -#Sat Jan 21 23:04:06 EET 2012 -eclipse.preferences.version=1 -editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true -sp_cleanup.add_default_serial_version_id=true -sp_cleanup.add_generated_serial_version_id=false -sp_cleanup.add_missing_annotations=true -sp_cleanup.add_missing_deprecated_annotations=true -sp_cleanup.add_missing_methods=false -sp_cleanup.add_missing_nls_tags=false -sp_cleanup.add_missing_override_annotations=true -sp_cleanup.add_missing_override_annotations_interface_methods=true -sp_cleanup.add_serial_version_id=false -sp_cleanup.always_use_blocks=true -sp_cleanup.always_use_parentheses_in_expressions=true -sp_cleanup.always_use_this_for_non_static_field_access=false -sp_cleanup.always_use_this_for_non_static_method_access=false -sp_cleanup.convert_to_enhanced_for_loop=true -sp_cleanup.correct_indentation=true -sp_cleanup.format_source_code=true -sp_cleanup.format_source_code_changes_only=true -sp_cleanup.make_local_variable_final=true -sp_cleanup.make_parameters_final=true -sp_cleanup.make_private_fields_final=false -sp_cleanup.make_type_abstract_if_missing_method=false -sp_cleanup.make_variable_declarations_final=true -sp_cleanup.never_use_blocks=false -sp_cleanup.never_use_parentheses_in_expressions=false -sp_cleanup.on_save_use_additional_actions=true -sp_cleanup.organize_imports=true -sp_cleanup.qualify_static_field_accesses_with_declaring_class=false -sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true -sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true -sp_cleanup.qualify_static_member_accesses_with_declaring_class=true -sp_cleanup.qualify_static_method_accesses_with_declaring_class=false -sp_cleanup.remove_private_constructors=true -sp_cleanup.remove_trailing_whitespaces=true -sp_cleanup.remove_trailing_whitespaces_all=true -sp_cleanup.remove_trailing_whitespaces_ignore_empty=false -sp_cleanup.remove_unnecessary_casts=true -sp_cleanup.remove_unnecessary_nls_tags=false -sp_cleanup.remove_unused_imports=true -sp_cleanup.remove_unused_local_variables=false -sp_cleanup.remove_unused_private_fields=true -sp_cleanup.remove_unused_private_members=false -sp_cleanup.remove_unused_private_methods=true -sp_cleanup.remove_unused_private_types=true -sp_cleanup.sort_members=false -sp_cleanup.sort_members_all=false -sp_cleanup.use_blocks=false -sp_cleanup.use_blocks_only_for_return_and_throw=false -sp_cleanup.use_parentheses_in_expressions=false -sp_cleanup.use_this_for_non_static_field_access=true -sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true -sp_cleanup.use_this_for_non_static_method_access=true -sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/spring-mvc-xml/.settings/org.eclipse.m2e.core.prefs b/spring-mvc-xml/.settings/org.eclipse.m2e.core.prefs deleted file mode 100644 index f897a7f1cb..0000000000 --- a/spring-mvc-xml/.settings/org.eclipse.m2e.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -activeProfiles= -eclipse.preferences.version=1 -resolveWorkspaceProjects=true -version=1 diff --git a/spring-mvc-xml/.settings/org.eclipse.m2e.wtp.prefs b/spring-mvc-xml/.settings/org.eclipse.m2e.wtp.prefs deleted file mode 100644 index ef86089622..0000000000 --- a/spring-mvc-xml/.settings/org.eclipse.m2e.wtp.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.m2e.wtp.enabledProjectSpecificPrefs=false diff --git a/spring-mvc-xml/.settings/org.eclipse.wst.common.component b/spring-mvc-xml/.settings/org.eclipse.wst.common.component deleted file mode 100644 index e54e3acac9..0000000000 --- a/spring-mvc-xml/.settings/org.eclipse.wst.common.component +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/spring-mvc-xml/.settings/org.eclipse.wst.common.project.facet.core.xml b/spring-mvc-xml/.settings/org.eclipse.wst.common.project.facet.core.xml deleted file mode 100644 index 9ca0d1c1b7..0000000000 --- a/spring-mvc-xml/.settings/org.eclipse.wst.common.project.facet.core.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/spring-mvc-xml/.settings/org.eclipse.wst.jsdt.ui.superType.container b/spring-mvc-xml/.settings/org.eclipse.wst.jsdt.ui.superType.container deleted file mode 100644 index 3bd5d0a480..0000000000 --- a/spring-mvc-xml/.settings/org.eclipse.wst.jsdt.ui.superType.container +++ /dev/null @@ -1 +0,0 @@ -org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/spring-mvc-xml/.settings/org.eclipse.wst.jsdt.ui.superType.name b/spring-mvc-xml/.settings/org.eclipse.wst.jsdt.ui.superType.name deleted file mode 100644 index 05bd71b6ec..0000000000 --- a/spring-mvc-xml/.settings/org.eclipse.wst.jsdt.ui.superType.name +++ /dev/null @@ -1 +0,0 @@ -Window \ No newline at end of file diff --git a/spring-mvc-xml/.settings/org.eclipse.wst.validation.prefs b/spring-mvc-xml/.settings/org.eclipse.wst.validation.prefs deleted file mode 100644 index 0d0aee4f72..0000000000 --- a/spring-mvc-xml/.settings/org.eclipse.wst.validation.prefs +++ /dev/null @@ -1,15 +0,0 @@ -DELEGATES_PREFERENCE=delegateValidatorList -USER_BUILD_PREFERENCE=enabledBuildValidatorListorg.eclipse.jst.j2ee.internal.classpathdep.ClasspathDependencyValidator; -USER_MANUAL_PREFERENCE=enabledManualValidatorListorg.eclipse.jst.j2ee.internal.classpathdep.ClasspathDependencyValidator; -USER_PREFERENCE=overrideGlobalPreferencestruedisableAllValidationfalseversion1.2.402.v201212031633 -disabled=06target -eclipse.preferences.version=1 -override=true -suspend=false -vals/org.eclipse.jst.jsf.ui.JSFAppConfigValidator/global=FF01 -vals/org.eclipse.jst.jsp.core.JSPBatchValidator/global=FF01 -vals/org.eclipse.jst.jsp.core.JSPContentValidator/global=FF01 -vals/org.eclipse.jst.jsp.core.TLDValidator/global=FF01 -vals/org.eclipse.wst.dtd.core.dtdDTDValidator/global=FF01 -vals/org.eclipse.wst.jsdt.web.core.JsBatchValidator/global=TF02 -vf.version=3 diff --git a/spring-mvc-xml/.settings/org.eclipse.wst.ws.service.policy.prefs b/spring-mvc-xml/.settings/org.eclipse.wst.ws.service.policy.prefs deleted file mode 100644 index 9cfcabe16f..0000000000 --- a/spring-mvc-xml/.settings/org.eclipse.wst.ws.service.policy.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.wst.ws.service.policy.projectEnabled=false diff --git a/spring-mvc-xml/.springBeans b/spring-mvc-xml/.springBeans deleted file mode 100644 index 7623a7e888..0000000000 --- a/spring-mvc-xml/.springBeans +++ /dev/null @@ -1,14 +0,0 @@ - - - 1 - - - - - - - src/main/webapp/WEB-INF/mvc-servlet.xml - - - - diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloController.java b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloController.java index 766aa6670a..cc9d66d4d4 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloController.java +++ b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloController.java @@ -7,10 +7,12 @@ import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.AbstractController; public class HelloController extends AbstractController { + @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView model = new ModelAndView("helloworld"); - model.addObject("msg", "!! Welcome to baeldung's Spring Handler Mappings Guide.
This is using SimpleUrlHandlerMapping."); + model.addObject("msg", "Welcome to Baeldung's Spring Handler Mappings Guide.
This request was mapped" + + " using SimpleUrlHandlerMapping."); return model; } diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloGuestController.java b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloGuestController.java index 5c19dc2295..614888ae42 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloGuestController.java +++ b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloGuestController.java @@ -10,7 +10,8 @@ public class HelloGuestController extends AbstractController { @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView model = new ModelAndView("helloworld"); - model.addObject("msg", "!! Welcome to baeldung's Spring Handler Mappings Guide.
This is using ControllerClassNameHandlerMapping."); + model.addObject("msg", "Welcome to Baeldung's Spring Handler Mappings Guide.
This request was mapped" + + " using ControllerClassNameHandlerMapping."); return model; } diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloWorldController.java b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloWorldController.java index 0659b3815d..6ed3d06ab7 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloWorldController.java +++ b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloWorldController.java @@ -10,7 +10,8 @@ public class HelloWorldController extends AbstractController { @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView model = new ModelAndView("helloworld"); - model.addObject("msg", "!! Welcome to baeldung's Spring Handler Mappings Guide.
This is using BeanNameUrlHandlerMapping."); + model.addObject("msg", "Welcome to Baeldung's Spring Handler Mappings Guide.
This request was mapped" + + " using BeanNameUrlHandlerMapping."); return model; } diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/WelcomeController.java b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/WelcomeController.java index e3c8bc5a25..5459481674 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/WelcomeController.java +++ b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/WelcomeController.java @@ -11,7 +11,8 @@ public class WelcomeController extends AbstractController { protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView model = new ModelAndView("welcome"); - model.addObject("msg", " baeldung's Spring Handler Mappings Guide.
This is using SimpleUrlHandlerMapping."); + model.addObject("msg", " Baeldung's Spring Handler Mappings Guide.
This request was mapped" + + " using SimpleUrlHandlerMapping."); return model; } diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-mvc-xml/src/main/webapp/WEB-INF/mvc-servlet.xml index 400c7b5e86..6cefb21961 100644 --- a/spring-mvc-xml/src/main/webapp/WEB-INF/mvc-servlet.xml +++ b/spring-mvc-xml/src/main/webapp/WEB-INF/mvc-servlet.xml @@ -1,57 +1,57 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd"> - - - - + + + + - - + + - + - - + + - - - - - welcomeController - welcomeController - helloController - - - - + + + + + welcomeController + welcomeController + helloController + + + + - - - + + + - - - - - + + + + + - - + + - - - + + + \ No newline at end of file diff --git a/spring-mvc-xml/src/main/webapp/index.jsp b/spring-mvc-xml/src/main/webapp/index.jsp index ef9279f6e5..ce7b3107d8 100644 --- a/spring-mvc-xml/src/main/webapp/index.jsp +++ b/spring-mvc-xml/src/main/webapp/index.jsp @@ -12,9 +12,7 @@

Spring MVC Examples

- diff --git a/spring-mvc-xml/src/main/webapp/spring-handler-index.jsp b/spring-mvc-xml/src/main/webapp/spring-handler-index.jsp index d915b344cb..0fdd51d1ec 100644 --- a/spring-mvc-xml/src/main/webapp/spring-handler-index.jsp +++ b/spring-mvc-xml/src/main/webapp/spring-handler-index.jsp @@ -1,26 +1,18 @@ -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" - pageEncoding="ISO-8859-1"%> - -Welcome + + Welcome -

Welcome to Spring Handler Mapping Example

-

Click below link to understand each mentioned Handler Mapping: -

-

- 1. BeanNameUrlHandlerMapping - - Mapping by bean name
-

- 2. SimpleUrlHandlerMapping -
-

- 3. ControllerClassNameHandlerMapping - - Mapping by controller name
-

- Go to spring handler mappings - homepage +

Spring Handler Mapping Examples

+

Click each link below to see how the request is mapped using the specified mapping: +

+
    +
  1. BeanNameUrlHandlerMapping - Mapping by bean name
  2. +
  3. SimpleUrlHandlerMapping
  4. +
  5. ControllerClassNameHandlerMapping - Mapping by controller name
  6. +
+Home \ No newline at end of file