Merge branch 'ivanp81-master'

This commit is contained in:
David Morley 2016-04-07 06:18:53 -05:00
commit 923f5c410a
40 changed files with 418 additions and 248 deletions

View File

@ -1,37 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -57,6 +57,13 @@
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<!-- common -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<!-- test scoped -->
<dependency>
<groupId>junit</groupId>

View File

@ -1,4 +1,4 @@
package org.baeldung.aop;
package com.baeldung.aop;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
@ -27,11 +27,11 @@ public class LoggingAspect {
public void repositoryMethods() {
}
@Pointcut("@annotation(org.baeldung.aop.annotations.Loggable)")
@Pointcut("@annotation(com.baeldung.aop.annotations.Loggable)")
public void loggableMethods() {
}
@Pointcut("@args(org.baeldung.aop.annotations.Entity)")
@Pointcut("@args(com.baeldung.aop.annotations.Entity)")
public void methodsAcceptingEntities() {
}

View File

@ -1,4 +1,4 @@
package org.baeldung.aop;
package com.baeldung.aop;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;

View File

@ -1,10 +1,10 @@
package org.baeldung.aop;
package com.baeldung.aop;
import com.baeldung.events.FooCreationEvent;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.baeldung.events.FooCreationEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

View File

@ -1,4 +1,4 @@
package org.baeldung.aop.annotations;
package com.baeldung.aop.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

View File

@ -1,4 +1,4 @@
package org.baeldung.aop.annotations;
package com.baeldung.aop.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

View File

@ -1,7 +1,7 @@
package org.baeldung.dao;
package com.baeldung.dao;
import org.baeldung.aop.annotations.Loggable;
import org.baeldung.model.Foo;
import com.baeldung.aop.annotations.Loggable;
import com.baeldung.model.Foo;
import org.springframework.stereotype.Repository;
@Repository

View File

@ -1,9 +1,9 @@
package org.baeldung.dialect;
package com.baeldung.dialect;
import java.util.HashSet;
import java.util.Set;
import org.baeldung.processor.NameProcessor;
import com.baeldung.processor.NameProcessor;
import org.thymeleaf.dialect.AbstractDialect;
import org.thymeleaf.processor.IProcessor;

View File

@ -1,4 +1,4 @@
package org.baeldung.events;
package com.baeldung.events;
import org.springframework.context.ApplicationEvent;

View File

@ -1,4 +1,4 @@
package org.baeldung.events;
package com.baeldung.events;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

View File

@ -1,4 +1,4 @@
package org.baeldung.model;
package com.baeldung.model;
import javax.xml.bind.annotation.XmlRootElement;

View File

@ -1,6 +1,6 @@
package org.baeldung.model;
package com.baeldung.model;
import org.baeldung.aop.annotations.Entity;
import com.baeldung.aop.annotations.Entity;
@Entity
public class Foo {

View File

@ -1,4 +1,4 @@
package org.baeldung.model;
package com.baeldung.model;
public class User {
private String firstname;

View File

@ -1,4 +1,4 @@
package org.baeldung.processor;
package com.baeldung.processor;
import org.thymeleaf.Arguments;
import org.thymeleaf.dom.Element;

View File

@ -0,0 +1,93 @@
package com.baeldung.spring.web.config;
import java.util.HashSet;
import java.util.Set;
import com.baeldung.dialect.CustomDialect;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Description;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
import org.thymeleaf.dialect.IDialect;
import org.thymeleaf.spring4.SpringTemplateEngine;
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
import org.thymeleaf.templateresolver.ServletContextTemplateResolver;
@EnableWebMvc
@Configuration
public class ClientWebConfig extends WebMvcConfigurerAdapter {
public ClientWebConfig() {
super();
}
// API
@Override
public void addViewControllers(final ViewControllerRegistry registry) {
super.addViewControllers(registry);
registry.addViewController("/sample.html");
}
@Bean
public ViewResolver thymeleafViewResolver() {
final ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
viewResolver.setTemplateEngine(templateEngine());
viewResolver.setOrder(1);
return viewResolver;
}
@Bean
public ViewResolver viewResolver() {
final InternalResourceViewResolver bean = new InternalResourceViewResolver();
bean.setViewClass(JstlView.class);
bean.setPrefix("/WEB-INF/view/");
bean.setSuffix(".jsp");
bean.setOrder(0);
return bean;
}
@Bean
@Description("Thymeleaf template resolver serving HTML 5")
public ServletContextTemplateResolver templateResolver() {
final ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
templateResolver.setPrefix("/WEB-INF/templates/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode("HTML5");
return templateResolver;
}
@Bean
@Description("Thymeleaf template engine with Spring integration")
public SpringTemplateEngine templateEngine() {
final SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver());
final Set<IDialect> dialects = new HashSet<>();
dialects.add(new CustomDialect());
templateEngine.setAdditionalDialects(dialects);
return templateEngine;
}
@Bean
@Description("Spring message resolver")
public MessageSource messageSource() {
final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("messages");
return messageSource;
}
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
}

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.web.config;
package com.baeldung.spring.web.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@ -0,0 +1,50 @@
package com.baeldung.spring.web.config;
import java.util.Set;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
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 {
private static final String TMP_FOLDER = "C:/Users/ivan/Desktop/tmp";
private static final int MAX_UPLOAD_SIZE = 5 * 1024 * 1024; // 5 MB
/**
* Register and configure all Servlet container components necessary to power the web application.
*/
@Override
public void onStartup(final ServletContext sc) throws ServletException {
// Create the 'root' Spring application context
final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
root.scan("com.baeldung.spring.web.config");
// root.getEnvironment().setDefaultProfiles("embedded");
// Manages the lifecycle of the root application context
sc.addListener(new ContextLoaderListener(root));
// Handles requests into the application
final ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext()));
appServlet.setLoadOnStartup(1);
// final MultipartConfigElement multipartConfigElement = new
// MultipartConfigElement(TMP_FOLDER, MAX_UPLOAD_SIZE,
// MAX_UPLOAD_SIZE * 2, MAX_UPLOAD_SIZE / 2);
//
// appServlet.setMultipartConfig(multipartConfigElement);
final Set<String> mappingConflicts = appServlet.addMapping("/");
if (!mappingConflicts.isEmpty()) {
throw new IllegalStateException("'appServlet' could not be mapped to '/' due " + "to an existing mapping. This is a known issue under Tomcat versions " + "<= 7.0.14; see https://issues.apache.org/bugzilla/show_bug.cgi?id=51278");
}
}
}

View File

@ -1,9 +1,10 @@
package org.baeldung.spring.web.config;
package com.baeldung.spring.web.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
@ -15,14 +16,26 @@ import org.springframework.web.servlet.view.XmlViewResolver;
@Configuration
@EnableWebMvc
@ComponentScan("org.baeldung.web")
@ComponentScan("com.baeldung.web")
public class WebConfig extends WebMvcConfigurerAdapter {
public WebConfig() {
super();
}
//
// @Bean
// public StandardServletMultipartResolver multipartResolver() {
// return new StandardServletMultipartResolver();
// }
@Bean(name = "multipartResolver")
public CommonsMultipartResolver multipartResolver() {
final CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
multipartResolver.setMaxUploadSize(100000);
return multipartResolver;
}
@Override
public void addViewControllers(final ViewControllerRegistry registry) {
@ -56,4 +69,4 @@ public class WebConfig extends WebMvcConfigurerAdapter {
return bean;
}
}
}

View File

@ -1,4 +1,4 @@
package org.baeldung.web;
package com.baeldung.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

View File

@ -1,4 +1,4 @@
package org.baeldung.web;
package com.baeldung.web;
import org.springframework.stereotype.Component;

View File

@ -1,9 +1,9 @@
package org.baeldung.web.controller;
package com.baeldung.web.controller;
import java.util.HashMap;
import java.util.Map;
import org.baeldung.model.Employee;
import com.baeldung.model.Employee;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;

View File

@ -0,0 +1,32 @@
package com.baeldung.web.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
@Controller
public class FileUploadController {
@RequestMapping(value = "/fileUpload", method = RequestMethod.GET)
public String displayForm() {
return "fileUploadForm";
}
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public String submit(@RequestParam("file") final MultipartFile file, final ModelMap modelMap) {
modelMap.addAttribute("file", file);
return "fileUploadView";
}
@RequestMapping(value = "/uploadMultiFile", method = RequestMethod.POST)
public String submit(@RequestParam("files") final MultipartFile[] files, final ModelMap modelMap) {
modelMap.addAttribute("files", files);
return "fileUploadView";
}
}

View File

@ -1,6 +1,6 @@
package org.baeldung.web.controller;
package com.baeldung.web.controller;
import org.baeldung.model.User;
import com.baeldung.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;

View File

@ -1,93 +0,0 @@
package org.baeldung.spring.web.config;
import java.util.HashSet;
import java.util.Set;
import org.baeldung.dialect.CustomDialect;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Description;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
import org.thymeleaf.dialect.IDialect;
import org.thymeleaf.spring4.SpringTemplateEngine;
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
import org.thymeleaf.templateresolver.ServletContextTemplateResolver;
@EnableWebMvc
@Configuration
public class ClientWebConfig extends WebMvcConfigurerAdapter {
public ClientWebConfig() {
super();
}
// API
@Override
public void addViewControllers(final ViewControllerRegistry registry) {
super.addViewControllers(registry);
registry.addViewController("/sample.html");
}
@Bean
public ViewResolver thymeleafViewResolver() {
final ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
viewResolver.setTemplateEngine(templateEngine());
viewResolver.setOrder(1);
return viewResolver;
}
@Bean
public ViewResolver viewResolver() {
final InternalResourceViewResolver bean = new InternalResourceViewResolver();
bean.setViewClass(JstlView.class);
bean.setPrefix("/WEB-INF/view/");
bean.setSuffix(".jsp");
bean.setOrder(0);
return bean;
}
@Bean
@Description("Thymeleaf template resolver serving HTML 5")
public ServletContextTemplateResolver templateResolver() {
final ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
templateResolver.setPrefix("/WEB-INF/templates/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode("HTML5");
return templateResolver;
}
@Bean
@Description("Thymeleaf template engine with Spring integration")
public SpringTemplateEngine templateEngine() {
final SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver());
final Set<IDialect> dialects = new HashSet<>();
dialects.add(new CustomDialect());
templateEngine.setAdditionalDialects(dialects);
return templateEngine;
}
@Bean
@Description("Spring message resolver")
public MessageSource messageSource() {
final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("messages");
return messageSource;
}
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
}

View File

@ -1,41 +0,0 @@
package org.baeldung.spring.web.config;
import java.util.Set;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
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 {
/**
* Register and configure all Servlet container components necessary to power the web application.
*/
@Override
public void onStartup(final ServletContext sc) throws ServletException {
System.out.println("MainWebAppInitializer.onStartup()");
// Create the 'root' Spring application context
final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
root.scan("org.baeldung.spring.web.config");
// root.getEnvironment().setDefaultProfiles("embedded");
// Manages the lifecycle of the root application context
sc.addListener(new ContextLoaderListener(root));
// Handles requests into the application
final ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext()));
appServlet.setLoadOnStartup(1);
final Set<String> mappingConflicts = appServlet.addMapping("/");
if (!mappingConflicts.isEmpty()) {
throw new IllegalStateException("'appServlet' could not be mapped to '/' due " + "to an existing mapping. This is a known issue under Tomcat versions " + "<= 7.0.14; see https://issues.apache.org/bugzilla/show_bug.cgi?id=51278");
}
}
}

View File

@ -7,8 +7,8 @@
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.2.xsd">
<bean id="perfomanceMeter" class="org.baeldung.aop.PerformanceAspect"/>
<bean id="fooDao" class="org.baeldung.dao.FooDao"/>
<bean id="perfomanceMeter" class="com.baeldung.aop.PerformanceAspect"/>
<bean id="fooDao" class="com.baeldung.dao.FooDao"/>
<aop:config>
<aop:pointcut id="anyDaoMethod" expression="@target(org.springframework.stereotype.Repository)"/>

View File

@ -0,0 +1,55 @@
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>File Upload Example</title>
</head>
<body>
<h3>Enter The File to Upload (Single file)</h3>
<form:form method="POST" action="/spring-mvc-java/uploadFile" enctype="multipart/form-data">
<table>
<tr>
<td>Select a file to upload</td>
<td><input type="file" name="file" /></td>
</tr>
<tr>
<td><input type="submit" value="Submit" /></td>
</tr>
</table>
</form:form>
<br />
<h3>Enter The Files to Upload (Multiple files)</h3>
<form:form method="POST" action="/spring-mvc-java/uploadMultiFile" enctype="multipart/form-data">
<table>
<tr>
<td>Select a file to upload</td>
<td><input type="file" name="files" /></td>
</tr>
<tr>
<td>Select a file to upload</td>
<td><input type="file" name="files" /></td>
</tr>
<tr>
<td>Select a file to upload</td>
<td><input type="file" name="files" /></td>
</tr>
<tr>
<td><input type="submit" value="Submit" /></td>
</tr>
</table>
</form:form>
</body>
</html>

View File

@ -0,0 +1,36 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>Spring MVC File Upload</title>
</head>
<body>
<h2>Submitted File (Single)</h2>
<table>
<tr>
<td>OriginalFileName :</td>
<td>${file.originalFilename}</td>
</tr>
<tr>
<td>Type :</td>
<td>${file.contentType}</td>
</tr>
</table>
<br />
<h2>Submitted Files (Multiple)</h2>
<table>
<c:forEach items="${files}" var="file">
<tr>
<td>OriginalFileName :</td>
<td>${file.originalFilename}</td>
</tr>
<tr>
<td>Type :</td>
<td>${file.contentType}</td>
</tr>
</c:forEach>
</table>
</body>
</html>

View File

@ -16,7 +16,7 @@
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>org.baeldung.spring.web.config</param-value>
<param-value>com.baeldung.spring.web.config</param-value>
</context-param>
<listener>

View File

@ -1,8 +1,8 @@
package org.baeldung.aop;
package com.baeldung.aop;
import org.baeldung.config.TestConfig;
import org.baeldung.dao.FooDao;
import org.baeldung.model.Foo;
import com.baeldung.config.TestConfig;
import com.baeldung.dao.FooDao;
import com.baeldung.model.Foo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -1,7 +1,7 @@
package org.baeldung.aop;
package com.baeldung.aop;
import org.baeldung.config.TestConfig;
import org.baeldung.dao.FooDao;
import com.baeldung.config.TestConfig;
import com.baeldung.dao.FooDao;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -1,9 +1,9 @@
package org.baeldung.aop;
package com.baeldung.aop;
import org.baeldung.config.TestConfig;
import org.baeldung.dao.FooDao;
import org.baeldung.events.FooCreationEventListener;
import org.baeldung.model.Foo;
import com.baeldung.config.TestConfig;
import com.baeldung.dao.FooDao;
import com.baeldung.events.FooCreationEventListener;
import com.baeldung.model.Foo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -1,6 +1,6 @@
package org.baeldung.aop;
package com.baeldung.aop;
import org.baeldung.dao.FooDao;
import com.baeldung.dao.FooDao;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -21,7 +21,7 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/org/baeldung/aop/beans.xml")
@ContextConfiguration("/com/baeldung/aop/beans.xml")
public class AopXmlConfigPerformanceTest {
@Before

View File

@ -1,11 +1,11 @@
package org.baeldung.config;
package com.baeldung.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@Configuration
@ComponentScan(basePackages = { "org.baeldung.dao", "org.baeldung.aop", "org.baeldung.events" })
@ComponentScan(basePackages = { "com.baeldung.dao", "com.baeldung.aop", "com.baeldung.events" })
@EnableAspectJAutoProxy
public class TestConfig {
}

View File

@ -8,10 +8,10 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
@Configuration
public class ClientWebConfig extends WebMvcConfigurerAdapter {
public ClientWebConfig() {
super();
}
public ClientWebConfig() {
super();
}
// API
// API
}

View File

@ -1,6 +1,12 @@
package com.baeldung.spring;
import java.util.Locale;
import java.util.ResourceBundle;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.MessageSourceResourceBundle;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@ -11,27 +17,40 @@ import org.springframework.web.servlet.view.JstlView;
//@Configuration
public class ClientWebConfigJava extends WebMvcConfigurerAdapter {
public ClientWebConfigJava() {
super();
}
public ClientWebConfigJava() {
super();
}
// API
@Bean
public MessageSource messageSource() {
@Override
public void addViewControllers(final ViewControllerRegistry registry) {
super.addViewControllers(registry);
final ResourceBundleMessageSource ms = new ResourceBundleMessageSource();
ms.setBasenames("messages");
return ms;
}
registry.addViewController("/sample.html");
}
@Bean
public ResourceBundle getBeanResourceBundle() {
@Bean
public ViewResolver viewResolver() {
final InternalResourceViewResolver bean = new InternalResourceViewResolver();
final Locale locale = Locale.getDefault();
return new MessageSourceResourceBundle(messageSource(), locale);
}
bean.setViewClass(JstlView.class);
bean.setPrefix("/WEB-INF/view/");
bean.setSuffix(".jsp");
@Override
public void addViewControllers(final ViewControllerRegistry registry) {
super.addViewControllers(registry);
return bean;
}
registry.addViewController("/sample.html");
}
@Bean
public ViewResolver viewResolver() {
final InternalResourceViewResolver bean = new InternalResourceViewResolver();
bean.setViewClass(JstlView.class);
bean.setPrefix("/WEB-INF/view/");
bean.setSuffix(".jsp");
return bean;
}
}

View File

@ -25,4 +25,4 @@
<property name="basename" value="messages" />
</bean>
</beans>
</beans>

View File

@ -24,7 +24,7 @@
<h3>Welcome, Enter the Person Details</h3>
<form:form method="POST" action="addPerson" modelAttribute="person">
<form:form method="POST" action="/spring-mvc-xml/addPerson" modelAttribute="person">
<form:errors path="*" cssClass="errorbox" element="div" />
@ -117,4 +117,4 @@
</body>
</html>
</html>

View File

@ -61,6 +61,5 @@
<td>${person.notes}</td>
</tr>
</table>
</body>
</html>
</html>