Unable to run spring template project on STS

2019-08-12 19:02发布

问题:

I created a template project named sample and started it with spring tc server. The application gets deployed but then when I go to http://localhost:8080/sample/ I get the following error

INFO: Server startup in 12669 ms WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/sample/] in DispatcherServlet with name 'appServlet'

I followed the same steps as shown in http://www.youtube.com/watch?v=Y0V4oEnCcyA to create a spring web App.

I asked my friend to follow the same steps and test it on his Ubuntu 10.04 machine and it worked fine out of the box. I came up with the conclusion that it must be something with my machine. I'm facing this problem on Mac osx 10.4 and SpringSource Tool Suite Version: 2.6.0.RELEASE

My host file contains the following entry

127.0.0.1 localhost

Can anyone guide me as to how to rectify this problem?

Thanks.

回答1:

That warning means that you didn't set something up right in your project, plain and simple. Without code we can only guess.

Speaking of guessing, check your web.xml and make sure it actually says "sample".



回答2:

Template project does not work for me either.

I changed the servlet mapping onto

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>

Follow up the request mapping in the controller

@RequestMapping(value = "/home.do", method = RequestMethod.GET)

Now you can open http://localhost:8080/sample/home.do



回答3:

Check the log in your eclipse server console window (bottom screen). If you're like me, there's a bug when resolving the path for the home.jsp file. It comes from the servlet-context.xml file :

<beans:property name="suffix" value="/" />

should be

<beans:property name="suffix" value=".jsp" />

Make sure you clean and restart the server after doing that change, because it seems like this servlet-context.xml file is heavily cached.