Merge pull request #4663 from eugenp/upgrade-xml

upgrade to spring 5, remove extra code
This commit is contained in:
Loredana Crusoveanu 2018-07-09 23:46:08 +03:00 committed by GitHub
commit 016509a21a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 16 additions and 180 deletions

View File

@ -10,7 +10,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
### Relevant Articles: ### Relevant Articles:
- [Spring MVC Tutorial](http://www.baeldung.com/spring-mvc-tutorial) - [Spring MVC Tutorial](http://www.baeldung.com/spring-mvc-tutorial)
- [Servlet Session Timeout](http://www.baeldung.com/servlet-session-timeout) - [Servlet Session Timeout](http://www.baeldung.com/servlet-session-timeout)
- [Basic Forms with Spring MVC](http://www.baeldung.com/spring-mvc-form-tutorial)
- [Returning Image/Media Data with Spring MVC](http://www.baeldung.com/spring-mvc-image-media-data) - [Returning Image/Media Data with Spring MVC](http://www.baeldung.com/spring-mvc-image-media-data)
- [Geolocation by IP in Java](http://www.baeldung.com/geolocation-by-ip-with-maxmind) - [Geolocation by IP in Java](http://www.baeldung.com/geolocation-by-ip-with-maxmind)
- [Guide to JavaServer Pages (JSP)](http://www.baeldung.com/jsp) - [Guide to JavaServer Pages (JSP)](http://www.baeldung.com/jsp)

View File

@ -37,13 +37,6 @@
<!-- web --> <!-- web -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.2</version>
</dependency>
<dependency> <dependency>
<groupId>javax.servlet</groupId> <groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId> <artifactId>javax.servlet-api</artifactId>
@ -127,10 +120,8 @@
<properties> <properties>
<!-- Spring --> <!-- Spring -->
<org.springframework.version>5.0.2.RELEASE</org.springframework.version> <org.springframework.version>5.0.2.RELEASE</org.springframework.version>
<org.springframework.security.version>4.2.0.RELEASE</org.springframework.security.version>
<!-- persistence --> <!-- persistence -->
<hibernate.version>5.2.5.Final</hibernate.version>
<mysql-connector-java.version>5.1.40</mysql-connector-java.version> <mysql-connector-java.version>5.1.40</mysql-connector-java.version>
<!-- http --> <!-- http -->
@ -138,10 +129,10 @@
<httpclient.version>4.5.2</httpclient.version> <httpclient.version>4.5.2</httpclient.version>
<!-- various --> <!-- various -->
<hibernate-validator.version>5.3.3.Final</hibernate-validator.version> <hibernate-validator.version>6.0.10.Final</hibernate-validator.version>
<jstl.version>1.2</jstl.version> <jstl.version>1.2</jstl.version>
<javax.servlet.version>3.1.0</javax.servlet.version> <javax.servlet.version>3.1.0</javax.servlet.version>
<jackson.version>2.8.5</jackson.version> <jackson.version>2.9.6</jackson.version>
<!-- util --> <!-- util -->
<guava.version>19.0</guava.version> <guava.version>19.0</guava.version>
@ -149,9 +140,6 @@
<commons-io.version>2.5</commons-io.version> <commons-io.version>2.5</commons-io.version>
<geoip2.version>2.8.0</geoip2.version> <geoip2.version>2.8.0</geoip2.version>
<!-- testing -->
<rest-assured.version>2.9.0</rest-assured.version>
<!-- Maven plugins --> <!-- Maven plugins -->
<maven-war-plugin.version>2.6</maven-war-plugin.version> <maven-war-plugin.version>2.6</maven-war-plugin.version>
<cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version> <cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version>

View File

@ -2,11 +2,11 @@ package com.baeldung.spring;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource; import org.springframework.context.annotation.ImportResource;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@ImportResource("classpath:webMvcConfig.xml") @ImportResource("classpath:webMvcConfig.xml")
@Configuration @Configuration
public class ClientWebConfig extends WebMvcConfigurerAdapter { public class ClientWebConfig implements WebMvcConfigurer {
public ClientWebConfig() { public ClientWebConfig() {
super(); super();

View File

@ -9,13 +9,13 @@ import org.springframework.context.support.MessageSourceResourceBundle;
import org.springframework.context.support.ResourceBundleMessageSource; import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView; import org.springframework.web.servlet.view.JstlView;
//@EnableWebMvc //@EnableWebMvc
//@Configuration //@Configuration
public class ClientWebConfigJava extends WebMvcConfigurerAdapter { public class ClientWebConfigJava implements WebMvcConfigurer {
public ClientWebConfigJava() { public ClientWebConfigJava() {
super(); super();
@ -38,8 +38,6 @@ public class ClientWebConfigJava extends WebMvcConfigurerAdapter {
@Override @Override
public void addViewControllers(final ViewControllerRegistry registry) { public void addViewControllers(final ViewControllerRegistry registry) {
super.addViewControllers(registry);
registry.addViewController("/sample.html"); registry.addViewController("/sample.html");
} }

View File

@ -1,45 +0,0 @@
package com.baeldung.spring.controller;
import java.util.HashMap;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.baeldung.spring.form.Employee;
@Controller
public class EmployeeController {
Map<Long, Employee> employeeMap = new HashMap<>();
@RequestMapping(value = "/employee", method = RequestMethod.GET)
public ModelAndView showForm() {
return new ModelAndView("employeeHome", "employee", new Employee());
}
@RequestMapping(value = "/employee/{Id}", produces = { "application/json", "application/xml" }, method = RequestMethod.GET)
public @ResponseBody Employee getEmployeeById(@PathVariable final long Id) {
return employeeMap.get(Id);
}
@RequestMapping(value = "/addEmployee", method = RequestMethod.POST)
public String submit(@ModelAttribute("employee") final Employee employee, final BindingResult result, final ModelMap model) {
if (result.hasErrors()) {
return "error";
}
model.addAttribute("name", employee.getName());
model.addAttribute("contactNumber", employee.getContactNumber());
model.addAttribute("id", employee.getId());
employeeMap.put(employee.getId(), employee);
return "employeeView";
}
}

View File

@ -11,7 +11,8 @@ import org.springframework.web.bind.annotation.ResponseBody;
import com.baeldung.spring.form.GeoIP; import com.baeldung.spring.form.GeoIP;
import com.baeldung.spring.service.RawDBDemoGeoIPLocationService; import com.baeldung.spring.service.RawDBDemoGeoIPLocationService;
@Controller //@Controller
//add db file and uncomment to see the working example
public class GeoIPTestController { public class GeoIPTestController {
private RawDBDemoGeoIPLocationService locationService; private RawDBDemoGeoIPLocationService locationService;

View File

@ -1,49 +0,0 @@
package com.baeldung.spring.form;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Employee {
private long id;
@NotNull
@Size(min = 1)
private String name;
@NotNull
@Size(min = 1)
private String contactNumber;
public Employee() {
super();
}
//
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public long getId() {
return id;
}
public void setId(final long id) {
this.id = id;
}
public String getContactNumber() {
return contactNumber;
}
public void setContactNumber(final String contactNumber) {
this.contactNumber = contactNumber;
}
}

View File

@ -2,7 +2,8 @@ package com.baeldung.spring.form;
import java.util.List; import java.util.List;
import org.hibernate.validator.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
public class Person { public class Person {

View File

@ -4,11 +4,11 @@
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation=" xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd"> http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" /> <mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" />
<context:component-scan base-package="com.baeldung.spring.controller" /> <context:component-scan base-package="com.baeldung.spring.controller" />

View File

@ -3,11 +3,11 @@
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation=" xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd" http://www.springframework.org/schema/mvc/spring-mvc.xsd"
> >
<mvc:annotation-driven> <mvc:annotation-driven>

View File

@ -1,33 +0,0 @@
<%@ 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>Form Example - Register an Employee</title>
</head>
<body>
<h3>Welcome, Enter The Employee Details</h3>
<form:form method="POST" action="/spring-mvc-xml/addEmployee" modelAttribute="employee">
<table>
<tr>
<td><form:label path="name">Name</form:label></td>
<td><form:input path="name" /></td>
</tr>
<tr>
<td><form:label path="id">Id</form:label></td>
<td><form:input path="id" /></td>
</tr>
<tr>
<td><form:label path="contactNumber">Contact Number</form:label></td>
<td><form:input path="contactNumber" /></td>
</tr>
<tr>
<td><input type="submit" value="Submit" /></td>
</tr>
</table>
</form:form>
</body>
</html>

View File

@ -1,24 +0,0 @@
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
<title>Spring MVC Form Handling</title>
</head>
<body>
<h2>Submitted Employee Information</h2>
<table>
<tr>
<td>Name :</td>
<td>${name}</td>
</tr>
<tr>
<td>ID :</td>
<td>${id}</td>
</tr>
<tr>
<td>Contact Number :</td>
<td>${contactNumber}</td>
</tr>
</table>
</body>
</html>