...
Now enter 'edu.asu.diging.tutorial.spring' in the field 'Group Id' and 'one' in the field 'Artifact Id'. Click 'Finish'. [If Maven archetype progress stalls, click into console to get cursor and press enter after 'Y : ']
Eclipse should now generate a new web application project for you called 'one'.
...
Info | ||
---|---|---|
| ||
Eclipse might show you an error marker on your project, claiming that " |
Let Spring take over
...
By adding target runtime to the project, http-servlet will be available to the project class-path. Alternatively, you can fix this by adding javax.servlet.jsp-api to the pom and mark the dependency as provided
|
Let Spring take over
Now, you are all setup to start with Spring. First, you need to tell Tomcat that you want Spring to handle incoming requests. You do this by specifying which servlet Tomcat should use as 'entry point' into your application. Open the file web.xml located in src > main > webapp > WEB-INF. Add the following code inside the 'web-app' tag after the 'display-name' section:
...
Code Block |
---|
<web-app id="WebApp_ID" version="3.1" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_3_1.xsd"> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/root-context.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> </web-app> |
After adding the web-app tag with schema, if you face any issue in your eclipse like "Download from external resource is disabled", you can enable it by Go to top bar: Window → Preferences → Maven → Check the option ("Download Artifact javadoc"). Then apply and close.
What did you just do? First, you specified a servlet that Tomcat should know (the 'servlet' section). You named the servlet 'dispatcher' and you told Tomcat that you wanted it to be of type 'org.springframework.web.servlet.DispatcherServlet'. You also told Tomcat to initialize the dispatcher servlet with a file named servlet-context.xml located in WEB-INF > spring > appServlet.
...