BAEL-1148 earth001@gmail.com - Merged spring-mvc-push module in spring-mvc-simple (#3459)
* Sample code for BAEL-1148 - earth001@gmail.com * Change tabs for spaces in non java files * Change tabs for spaces in non java files * Removed unnecessary argument * BAEL-1148 earth001@gmail.com - Mapped get method in controller / Removed resources * Merged spring-mvc-push module in spring-mvc-simple
This commit is contained in:
parent
a115c94f32
commit
b1266c833b
|
@ -1 +0,0 @@
|
||||||
/.tern-project
|
|
|
@ -1,91 +0,0 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>spring-mvc-push</artifactId>
|
|
||||||
<packaging>war</packaging>
|
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
|
||||||
<name>spring-mvc-push</name>
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
|
||||||
<maven-surefire-plugin.version>2.20</maven-surefire-plugin.version>
|
|
||||||
<maven.compiler.version>3.7.0</maven.compiler.version>
|
|
||||||
<maven-war-plugin.version>3.2.0</maven-war-plugin.version>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<junit.jupiter.version>5.0.2</junit.jupiter.version>
|
|
||||||
<spring.version>5.0.2.RELEASE</spring.version>
|
|
||||||
<servlet.version>4.0.0</servlet.version>
|
|
||||||
<jstl.version>1.2</jstl.version>
|
|
||||||
<jsp-api.version>2.3.2-b02</jsp-api.version>
|
|
||||||
<junit.jupiter.version>5.0.2</junit.jupiter.version>
|
|
||||||
<junit.platform.version>1.0.2</junit.platform.version>
|
|
||||||
</properties>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-webmvc</artifactId>
|
|
||||||
<version>${spring.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.servlet</groupId>
|
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
|
||||||
<version>${servlet.version}</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.servlet</groupId>
|
|
||||||
<artifactId>jstl</artifactId>
|
|
||||||
<version>${jstl.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.servlet.jsp</groupId>
|
|
||||||
<artifactId>javax.servlet.jsp-api</artifactId>
|
|
||||||
<version>${jsp-api.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<!--Testing -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-test</artifactId>
|
|
||||||
<version>${spring.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.jupiter</groupId>
|
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
|
||||||
<version>${junit.jupiter.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>${maven.compiler.version}</version>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-war-plugin</artifactId>
|
|
||||||
<version>${maven-war-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<warName>spring-mvc-push</warName>
|
|
||||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
|
||||||
<outputDirectory>${deploy-path}</outputDirectory>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
<version>${maven-surefire-plugin.version}</version>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.platform</groupId>
|
|
||||||
<artifactId>junit-platform-surefire-provider</artifactId>
|
|
||||||
<version>${junit.platform.version}</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
<finalName>spring-mvc-push</finalName>
|
|
||||||
</build>
|
|
||||||
</project>
|
|
|
@ -1,48 +0,0 @@
|
||||||
package com.baeldung.config;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.ServletRegistration;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.web.WebApplicationInitializer;
|
|
||||||
import org.springframework.web.context.ContextLoaderListener;
|
|
||||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
|
||||||
import org.springframework.web.servlet.DispatcherServlet;
|
|
||||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
||||||
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableWebMvc
|
|
||||||
@ComponentScan(basePackages = "com.baeldung.controller")
|
|
||||||
public class PushConfiguration implements WebApplicationInitializer, WebMvcConfigurer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStartup(ServletContext container) throws ServletException {
|
|
||||||
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
|
||||||
context.register(PushConfiguration.class);
|
|
||||||
container.addListener(new ContextLoaderListener(context));
|
|
||||||
ServletRegistration.Dynamic dispatcher = container.addServlet("DispatcherServlet", new DispatcherServlet(context));
|
|
||||||
dispatcher.setLoadOnStartup(1);
|
|
||||||
dispatcher.addMapping("/");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public InternalResourceViewResolver jspViewResolver() {
|
|
||||||
InternalResourceViewResolver bean = new InternalResourceViewResolver();
|
|
||||||
bean.setPrefix("/WEB-INF/views/");
|
|
||||||
bean.setSuffix(".jsp");
|
|
||||||
return bean;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
||||||
registry.addResourceHandler("/resources/**")
|
|
||||||
.addResourceLocations("/resources/");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
|
||||||
pageEncoding="UTF-8"%>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
||||||
<title>PushBuilder demo</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h4>
|
|
||||||
Go to <a href="demoWithPush">PushBuilder demo</a><br> Go to
|
|
||||||
<a href="demoWithoutPush">Simple demo</a>
|
|
||||||
</h4>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1 +0,0 @@
|
||||||
console.log('Script')
|
|
|
@ -1,9 +0,0 @@
|
||||||
.single-title {
|
|
||||||
font-size: 30px;
|
|
||||||
color: #535353;
|
|
||||||
font-weight: 200;
|
|
||||||
letter-spacing: -1.5px;
|
|
||||||
line-height: 64px;
|
|
||||||
max-width: 750px;
|
|
||||||
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif
|
|
||||||
}
|
|
|
@ -8,82 +8,61 @@
|
||||||
<name>Spring MVC simple Maven Webapp</name>
|
<name>Spring MVC simple Maven Webapp</name>
|
||||||
<url>http://maven.apache.org</url>
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>parent-modules</artifactId>
|
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<springframework.version>4.3.10.RELEASE</springframework.version>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven-war-plugin.version>3.1.0</maven-war-plugin.version>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<springframework.version>5.0.2.RELEASE</springframework.version>
|
||||||
|
<maven-war-plugin.version>3.2.0</maven-war-plugin.version>
|
||||||
|
<maven.compiler.version>3.7.0</maven.compiler.version>
|
||||||
|
<maven-surefire-plugin.version>2.20</maven-surefire-plugin.version>
|
||||||
<jstl.version>1.2</jstl.version>
|
<jstl.version>1.2</jstl.version>
|
||||||
<javax.servlet.jsp-api.version>2.3.1</javax.servlet.jsp-api.version>
|
<javax.servlet.jsp-api.version>2.3.2-b02</javax.servlet.jsp-api.version>
|
||||||
<javax.servlet-api.version>3.1.0</javax.servlet-api.version>
|
<javax.servlet-api.version>4.0.0</javax.servlet-api.version>
|
||||||
<hibernate-validator.version>5.4.1.Final</hibernate-validator.version>
|
<hibernate-validator.version>5.4.1.Final</hibernate-validator.version>
|
||||||
<deploy-path>enter-location-of-server</deploy-path>
|
<deploy-path>enter-location-of-server</deploy-path>
|
||||||
<fileupload.version>1.3.2</fileupload.version>
|
<fileupload.version>1.3.2</fileupload.version>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<org.thymeleaf-version>3.0.7.RELEASE</org.thymeleaf-version>
|
<org.thymeleaf-version>3.0.7.RELEASE</org.thymeleaf-version>
|
||||||
<groovy.version>2.4.12</groovy.version>
|
<groovy.version>2.4.12</groovy.version>
|
||||||
<freemarker.version>2.3.23</freemarker.version>
|
<freemarker.version>2.3.27-incubating</freemarker.version>
|
||||||
<jade.version>1.2.5</jade.version>
|
<jade.version>1.2.5</jade.version>
|
||||||
|
<junit.jupiter.version>5.0.2</junit.jupiter.version>
|
||||||
|
<junit.jupiter.version>5.0.2</junit.jupiter.version>
|
||||||
|
<junit.platform.version>1.0.2</junit.platform.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>${javax.servlet-api.version}</version>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-webmvc</artifactId>
|
|
||||||
<version>${springframework.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-context</artifactId>
|
|
||||||
<version>${springframework.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-core</artifactId>
|
|
||||||
<version>${springframework.version}</version>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<artifactId>commons-logging</artifactId>
|
|
||||||
<groupId>commons-logging</groupId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet.jsp</groupId>
|
<groupId>javax.servlet.jsp</groupId>
|
||||||
<artifactId>javax.servlet.jsp-api</artifactId>
|
<artifactId>javax.servlet.jsp-api</artifactId>
|
||||||
<version>${javax.servlet.jsp-api.version}</version>
|
<version>${javax.servlet.jsp-api.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>jstl</artifactId>
|
<artifactId>jstl</artifactId>
|
||||||
<version>${jstl.version}</version>
|
<version>${jstl.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate</groupId>
|
||||||
<artifactId>hibernate-validator</artifactId>
|
<artifactId>hibernate-validator</artifactId>
|
||||||
<version>${hibernate-validator.version}</version>
|
<version>${hibernate-validator.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-webmvc</artifactId>
|
|
||||||
<version>${springframework.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-fileupload</groupId>
|
<groupId>commons-fileupload</groupId>
|
||||||
<artifactId>commons-fileupload</artifactId>
|
<artifactId>commons-fileupload</artifactId>
|
||||||
<version>${fileupload.version}</version>
|
<version>${fileupload.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-webmvc</artifactId>
|
||||||
|
<version>${springframework.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- thymeleaf dependencies -->
|
<!-- thymeleaf dependencies -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -123,6 +102,19 @@
|
||||||
<version>${jade.version}</version>
|
<version>${jade.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--Testing -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-test</artifactId>
|
||||||
|
<version>${springframework.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<version>${junit.jupiter.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<pluginManagement>
|
<pluginManagement>
|
||||||
|
@ -141,11 +133,18 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.7.0</version>
|
<version>${maven.compiler.version}</version>
|
||||||
<configuration>
|
</plugin>
|
||||||
<source>1.8</source>
|
<plugin>
|
||||||
<target>1.8</target>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
</configuration>
|
<version>${maven-surefire-plugin.version}</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.platform</groupId>
|
||||||
|
<artifactId>junit-platform-surefire-provider</artifactId>
|
||||||
|
<version>${junit.platform.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</pluginManagement>
|
</pluginManagement>
|
||||||
|
|
|
@ -7,13 +7,13 @@ import org.springframework.web.multipart.MultipartResolver;
|
||||||
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
||||||
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
|
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
|
||||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
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.InternalResourceViewResolver;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebMvc
|
@EnableWebMvc
|
||||||
@ComponentScan(basePackages = { "com.baeldung.springmvcforms", "com.baeldung.spring.controller", "com.baeldung.spring.validator" })
|
@ComponentScan(basePackages = { "com.baeldung.springmvcforms", "com.baeldung.spring.controller", "com.baeldung.spring.validator" })
|
||||||
class ApplicationConfiguration extends WebMvcConfigurerAdapter {
|
class ApplicationConfiguration implements WebMvcConfigurer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
|
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
|
||||||
|
|
|
@ -16,24 +16,24 @@ import de.neuland.jade4j.spring.view.JadeViewResolver;
|
||||||
public class JadeTemplateConfiguration {
|
public class JadeTemplateConfiguration {
|
||||||
@Bean
|
@Bean
|
||||||
public SpringTemplateLoader templateLoader() {
|
public SpringTemplateLoader templateLoader() {
|
||||||
SpringTemplateLoader templateLoader = new SpringTemplateLoader();
|
SpringTemplateLoader templateLoader = new SpringTemplateLoader();
|
||||||
templateLoader.setBasePath("/WEB-INF/views/");
|
templateLoader.setBasePath("/WEB-INF/views/");
|
||||||
templateLoader.setSuffix(".jade");
|
templateLoader.setSuffix(".jade");
|
||||||
return templateLoader;
|
return templateLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public JadeConfiguration jadeConfiguration() {
|
public JadeConfiguration jadeConfiguration() {
|
||||||
JadeConfiguration configuration = new JadeConfiguration();
|
JadeConfiguration configuration = new JadeConfiguration();
|
||||||
configuration.setCaching(false);
|
configuration.setCaching(false);
|
||||||
configuration.setTemplateLoader(templateLoader());
|
configuration.setTemplateLoader(templateLoader());
|
||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ViewResolver viewResolver() {
|
public ViewResolver viewResolver() {
|
||||||
JadeViewResolver viewResolver = new JadeViewResolver();
|
JadeViewResolver viewResolver = new JadeViewResolver();
|
||||||
viewResolver.setConfiguration(jadeConfiguration());
|
viewResolver.setConfiguration(jadeConfiguration());
|
||||||
return viewResolver;
|
return viewResolver;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.baeldung.spring.configuration;
|
||||||
|
|
||||||
|
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.EnableWebMvc;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableWebMvc
|
||||||
|
@ComponentScan(basePackages = "com.baeldung.spring.controller.push")
|
||||||
|
public class PushConfiguration implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public InternalResourceViewResolver jspViewResolver() {
|
||||||
|
InternalResourceViewResolver bean = new InternalResourceViewResolver();
|
||||||
|
bean.setPrefix("/WEB-INF/views/");
|
||||||
|
bean.setSuffix(".jsp");
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
|
registry.addResourceHandler("/resources/**")
|
||||||
|
.addResourceLocations("/resources/");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -11,42 +11,23 @@ import javax.servlet.ServletRegistration;
|
||||||
|
|
||||||
public class WebInitializer implements WebApplicationInitializer {
|
public class WebInitializer implements WebApplicationInitializer {
|
||||||
|
|
||||||
public void onStartup(ServletContext container) throws ServletException {
|
public void onStartup(ServletContext container) throws ServletException {
|
||||||
|
|
||||||
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
|
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
|
||||||
ctx.register(ApplicationConfiguration.class);
|
ctx.register(ApplicationConfiguration.class);
|
||||||
//ctx.register(ThymeleafConfiguration.class);
|
// ctx.register(ThymeleafConfiguration.class);
|
||||||
//ctx.register(FreemarkerConfiguration.class);
|
// ctx.register(FreemarkerConfiguration.class);
|
||||||
//ctx.register(GroovyConfiguration.class);
|
// ctx.register(GroovyConfiguration.class);
|
||||||
//ctx.register(JadeTemplateConfiguration.class);
|
// ctx.register(JadeTemplateConfiguration.class);
|
||||||
ctx.setServletContext(container);
|
// ctx.register(PushConfiguration.class);
|
||||||
|
// ctx.setServletContext(container);
|
||||||
|
|
||||||
// Manage the lifecycle of the root application context
|
// Manage the lifecycle of the root application context
|
||||||
container.addListener(new ContextLoaderListener(ctx));
|
container.addListener(new ContextLoaderListener(ctx));
|
||||||
|
|
||||||
ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx));
|
ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx));
|
||||||
|
|
||||||
servlet.setLoadOnStartup(1);
|
servlet.setLoadOnStartup(1);
|
||||||
servlet.addMapping("/");
|
servlet.addMapping("/");
|
||||||
|
}
|
||||||
}
|
|
||||||
// @Override
|
|
||||||
// public void onStartup(ServletContext container) {
|
|
||||||
// // Create the 'root' Spring application context
|
|
||||||
// AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
|
|
||||||
// rootContext.register(ServiceConfig.class, JPAConfig.class, SecurityConfig.class);
|
|
||||||
//
|
|
||||||
// // Manage the lifecycle of the root application context
|
|
||||||
// container.addListener(new ContextLoaderListener(rootContext));
|
|
||||||
//
|
|
||||||
// // Create the dispatcher servlet's Spring application context
|
|
||||||
// AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext();
|
|
||||||
// dispatcherServlet.register(MvcConfig.class);
|
|
||||||
//
|
|
||||||
// // Register and map the dispatcher servlet
|
|
||||||
// ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherServlet));
|
|
||||||
// dispatcher.setLoadOnStartup(1);
|
|
||||||
// dispatcher.addMapping("/");
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,10 @@ import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class AnnotationMethodHandlerAdapterExample {
|
public class AnnotationMethodHandlerAdapterExample {
|
||||||
@RequestMapping("/annotedName")
|
@RequestMapping("/annotedName")
|
||||||
public ModelAndView getEmployeeName() {
|
public ModelAndView getEmployeeName() {
|
||||||
ModelAndView model = new ModelAndView("Greeting");
|
ModelAndView model = new ModelAndView("Greeting");
|
||||||
model.addObject("message", "Dinesh");
|
model.addObject("message", "Dinesh");
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -23,13 +23,13 @@ public class FileUploadController implements HandlerExceptionResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
|
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
|
||||||
public ModelAndView uploadFile(MultipartFile file) throws IOException{
|
public ModelAndView uploadFile(MultipartFile file) throws IOException {
|
||||||
ModelAndView modelAndView = new ModelAndView("file");
|
ModelAndView modelAndView = new ModelAndView("file");
|
||||||
|
|
||||||
InputStream in = file.getInputStream();
|
InputStream in = file.getInputStream();
|
||||||
File currDir = new File(".");
|
File currDir = new File(".");
|
||||||
String path = currDir.getAbsolutePath();
|
String path = currDir.getAbsolutePath();
|
||||||
FileOutputStream f = new FileOutputStream(path.substring(0, path.length()-1)+ file.getOriginalFilename());
|
FileOutputStream f = new FileOutputStream(path.substring(0, path.length() - 1) + file.getOriginalFilename());
|
||||||
int ch = 0;
|
int ch = 0;
|
||||||
while ((ch = in.read()) != -1) {
|
while ((ch = in.read()) != -1) {
|
||||||
f.write(ch);
|
f.write(ch);
|
||||||
|
@ -37,7 +37,8 @@ public class FileUploadController implements HandlerExceptionResolver {
|
||||||
f.flush();
|
f.flush();
|
||||||
f.close();
|
f.close();
|
||||||
|
|
||||||
modelAndView.getModel().put("message", "File uploaded successfully!");
|
modelAndView.getModel()
|
||||||
|
.put("message", "File uploaded successfully!");
|
||||||
return modelAndView;
|
return modelAndView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +46,8 @@ public class FileUploadController implements HandlerExceptionResolver {
|
||||||
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object object, Exception exc) {
|
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object object, Exception exc) {
|
||||||
ModelAndView modelAndView = new ModelAndView("file");
|
ModelAndView modelAndView = new ModelAndView("file");
|
||||||
if (exc instanceof MaxUploadSizeExceededException) {
|
if (exc instanceof MaxUploadSizeExceededException) {
|
||||||
modelAndView.getModel().put("message", "File size exceeds limit!");
|
modelAndView.getModel()
|
||||||
|
.put("message", "File size exceeds limit!");
|
||||||
}
|
}
|
||||||
return modelAndView;
|
return modelAndView;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,10 @@ import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class RequestMappingHandlerAdapterExample {
|
public class RequestMappingHandlerAdapterExample {
|
||||||
@RequestMapping("/requestName")
|
@RequestMapping("/requestName")
|
||||||
public ModelAndView getEmployeeName() {
|
public ModelAndView getEmployeeName() {
|
||||||
ModelAndView model = new ModelAndView("Greeting");
|
ModelAndView model = new ModelAndView("Greeting");
|
||||||
model.addObject("message", "Madhwal");
|
model.addObject("message", "Madhwal");
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,13 +6,11 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
import org.springframework.web.servlet.mvc.AbstractController;
|
import org.springframework.web.servlet.mvc.AbstractController;
|
||||||
|
|
||||||
public class SimpleControllerHandlerAdapterExample extends
|
public class SimpleControllerHandlerAdapterExample extends AbstractController {
|
||||||
AbstractController {
|
@Override
|
||||||
@Override
|
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
protected ModelAndView handleRequestInternal(HttpServletRequest request,
|
ModelAndView model = new ModelAndView("Greeting");
|
||||||
HttpServletResponse response) throws Exception {
|
model.addObject("message", "Dinesh Madhwal");
|
||||||
ModelAndView model = new ModelAndView("Greeting");
|
return model;
|
||||||
model.addObject("message", "Dinesh Madhwal");
|
}
|
||||||
return model;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package com.baeldung.controller;
|
package com.baeldung.spring.controller.push;
|
||||||
|
|
||||||
import javax.servlet.http.PushBuilder;
|
import javax.servlet.http.PushBuilder;
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
|
||||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
|
||||||
xmlns:context="http://www.springframework.org/schema/context"
|
|
||||||
xsi:schemaLocation=
|
|
||||||
"http://www.springframework.org/schema/mvc
|
|
||||||
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
|
|
||||||
http://www.springframework.org/schema/tx
|
|
||||||
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
|
|
||||||
http://www.springframework.org/schema/beans
|
|
||||||
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
|
||||||
http://www.springframework.org/schema/context
|
|
||||||
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
|
|
||||||
<context:component-scan base-package="com.baeldung.spring.controller" />
|
|
||||||
<bean
|
|
||||||
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
|
|
||||||
<bean
|
|
||||||
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
|
|
||||||
<bean id="viewResolver"
|
|
||||||
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
|
||||||
<property name="prefix" value="/WEB-INF/views/" />
|
|
||||||
<property name="suffix" value=".jsp" />
|
|
||||||
</bean>
|
|
||||||
</beans>
|
|
|
@ -1,28 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
|
||||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
|
||||||
xmlns:context="http://www.springframework.org/schema/context"
|
|
||||||
xsi:schemaLocation=
|
|
||||||
"http://www.springframework.org/schema/mvc
|
|
||||||
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
|
|
||||||
http://www.springframework.org/schema/tx
|
|
||||||
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
|
|
||||||
http://www.springframework.org/schema/beans
|
|
||||||
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
|
||||||
http://www.springframework.org/schema/context
|
|
||||||
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
|
|
||||||
<context:component-scan base-package="com.baeldung.spring.controller" />
|
|
||||||
<bean
|
|
||||||
class=
|
|
||||||
"org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
|
|
||||||
<bean
|
|
||||||
class=
|
|
||||||
"org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
|
|
||||||
<bean id="viewResolver"
|
|
||||||
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
|
||||||
<property name="prefix" value="/WEB-INF/views/" />
|
|
||||||
<property name="suffix" value=".jsp" />
|
|
||||||
</bean>
|
|
||||||
</beans>
|
|
|
@ -1,25 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
|
||||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
|
||||||
xmlns:context="http://www.springframework.org/schema/context"
|
|
||||||
xsi:schemaLocation=
|
|
||||||
"http://www.springframework.org/schema/mvc
|
|
||||||
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
|
|
||||||
http://www.springframework.org/schema/tx
|
|
||||||
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
|
|
||||||
http://www.springframework.org/schema/beans
|
|
||||||
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
|
||||||
http://www.springframework.org/schema/context
|
|
||||||
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
|
|
||||||
<bean id="HandlerMapping"
|
|
||||||
class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
|
|
||||||
<bean name="/greeting.html"
|
|
||||||
class="com.baeldung.spring.controller.SimpleControllerHandlerAdapterExample"/>
|
|
||||||
<bean id="viewResolver"
|
|
||||||
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
|
||||||
<property name="prefix" value="/WEB-INF/views/" />
|
|
||||||
<property name="suffix" value=".jsp" />
|
|
||||||
</bean>
|
|
||||||
</beans>
|
|
|
@ -12,7 +12,6 @@
|
||||||
<img src="<c:url value="/resources/logo.png"/>" alt="Logo"
|
<img src="<c:url value="/resources/logo.png"/>" alt="Logo"
|
||||||
height="126" width="411">
|
height="126" width="411">
|
||||||
<br>
|
<br>
|
||||||
<br> Go to
|
<!-- Content -->
|
||||||
<a href="/spring-mvc-push/">index</a>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -4,7 +4,7 @@ html
|
||||||
title User Registration
|
title User Registration
|
||||||
body
|
body
|
||||||
form(action="register" method="post" )
|
form(action="register" method="post" )
|
||||||
label(for="email") Emailaaaaaaaa:
|
label(for="email") Email:
|
||||||
input(type="text" name="email")
|
input(type="text" name="email")
|
||||||
label(for="password") Password:
|
label(for="password") Password:
|
||||||
input(type="password" name="password")
|
input(type="password" name="password")
|
||||||
|
|
Before Width: | Height: | Size: 7.2 KiB After Width: | Height: | Size: 7.2 KiB |
|
@ -1,10 +1,9 @@
|
||||||
package com.baeldung.controller;
|
package com.baeldung.controller.push;
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Disabled;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
|
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
|
||||||
|
@ -12,9 +11,8 @@ import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
import com.baeldung.config.PushConfiguration;
|
import com.baeldung.spring.configuration.PushConfiguration;
|
||||||
|
|
||||||
@Disabled
|
|
||||||
@SpringJUnitWebConfig(PushConfiguration.class)
|
@SpringJUnitWebConfig(PushConfiguration.class)
|
||||||
public class PushControllerIntegrationTest {
|
public class PushControllerIntegrationTest {
|
||||||
@Autowired
|
@Autowired
|
Loading…
Reference in New Issue