How to do it...

After creating the project, certain Maven errors will be encountered just like in Chapter 1, Getting Started with Spring. Bug-fix the Maven issues in our ch02-xml project in order to use the XML-based Spring 5.0 container by performing the following steps:

  1. Open pom.xml for the project and add the following properties, which contain the Spring build version and servlet container to utilize.
<properties> 
  <spring.version>5.0.0.BUILD-SNAPSHOT</spring.version> 
  <servlet.api.version>3.1.0</servlet.api.version> 
</properties> 
  1. Add also the following Spring 5 dependencies in pom.xml, which are essential in providing us with the interfaces and classes to build our Spring container:
<dependencies> 
  <dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-context</artifactId> 
    <version>${spring.version}</version> 
  </dependency> 
  <dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-core</artifactId> 
    <version>${spring.version}</version> 
  </dependency> 
  <dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-beans</artifactId> 
    <version>${spring.version}</version> 
  </dependency> 
</dependencies> 
  1. It is required to add the following repositories in pom.xml where all the Spring 5.0 dependencies in Step 2 will be downloaded through Maven:
<repositories> 
  <repository> 
  <id>spring-snapshots</id> 
  <name>Spring Snapshots</name> 
  <url>https://repo.spring.io/libs-snapshot</url> 
  <snapshots><enabled>true</enabled></snapshots> 
  </repository> 
</repositories> 
  1. Then add the Maven plugin for deployment in pom.xml but be sure to recognize web.xml as the deployment descriptor. This can be done by enabling <failOnMissingWebXml> or just deleting the <configuration> tag as follows:
<plugin> 
  <artifactId>maven-war-plugin</artifactId> 
  <version>2.3</version> 
  </plugin> 
<plugin> 
  1. Add the rest of the Tomcat Maven plugin for deployment in pom.xml, as explained in Chapter 1, Getting Started with Spring.
  2. After the Maven configuration details, check if there is a WEB-INF folder inside srcmainwebapp. If there isn't, create one. This is mandatory for this project since we will be using a deployment descriptor (or web.xml).
  3. Inside the WEB-INF folder, create a deployment descriptor or drop a web.xml template inside the srcmainwebappWEB-INF directory.
  1. Then create an XML-based Spring container named ch02-beans.xml inside the ch02-xmlsrcmainjava directory. The configuration file must contain the following namespaces and tags:
<?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:context="http://www.springframework.org/schema/context" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd"> 
</beans> 
You can generate this file using the STS Eclipse Wizard (Ctrl-N) and under the module SpringàSpring Bean Configuration File option.
  1. Save all the files. Then clean and build the Maven project. Do not deploy yet because this is just a standalone project at the moment.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.179.220