I'm having some trouble getting my Spring MVC project to serve a view to my localhost. I created a project from within Spring Tool Suite using the New -> Spring Project -> Spring MVC Project option. I have not modified this code at all, as I'm confident that this should work the way it is (but obviously it isn't).
Here is my project structure and HomeController.java
This theoretically should bring up home.jsp when I go to localhost, but instead brings up the basic Pivotal server page:
In my HomeController.java file, if I change the #RequestMapping(value) to "/testing", I get a 404 error:
Finally, here is my ServletContext.xml (which contains my ViewResolver that came with the Spring MVC Project template):
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
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">
<annotation-driven />
<resources mapping="/resources/**" location="/resources/" />
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="pear.pear.pear" />
</beans:beans>
And my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<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>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
How can I resolve this issue? What am I doing wrong? Also, on a side note, I've noticed in many other Spring tutorials that they use an Application.java driver class - is that necessary?
Thanks a lot.
Your app is probably not running on the root URL in Tomcat (/). the default would be the same name as the project, e.g. http://localhost:8080/hello/testing.
Attempt - 1: Change the context root defined in Project-->Properties-->Web Project Settings to "/" and restart the server (this did not work)
Attempt - 2: Locate the server.xml used by vfabric server and change the value "/" for your docbase and restart the server viola it worked !
Screenshot
It's funny when a spring MVC project is created with STS the tool automatically assigns the last few characters of the package structure you enter while creating the toplevelpackage as the context path for your web application, in your case if you access the web project with http://localhost:8080/pear you would be able to load the home page.
Related
I am new to spring mvc and tomcat.
I have developed a demo spring mvc project and trying to deploy it on tomcat 9 through eclipse.
Server starts successfully but when i try to access the url from browser i get 404 with below error message on screen. :
Message The requested resource [/spring-mvc-demo/] is not available
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Below are my code details :
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>spring-mvc-demo</display-name>
<absolute-ordering />
<!-- Spring MVC Configs -->
<!-- Step 1: Configure Spring MVC Dispatcher Servlet -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc-demo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Step 2: Set up URL mapping for Spring MVC Dispatcher Servlet -->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/spring-mvc-demo</url-pattern>
</servlet-mapping>
</web-app>
spring-mvc-demo-servlet.xml
<?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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- Step 3: Add support for component scanning -->
<context:component-scan base-package="main.webapp" />
<!-- Step 4: Add support for conversion, formatting and validation support -->
<mvc:annotation-driven/>
<!-- Step 5: Define Spring MVC view resolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
HomeController.java
package main.webapp.springdemo.controller;
import javax.annotation.PostConstruct;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class HomeController {
#PostConstruct
public void init() {
System.out.println("HomeController bean getting intiated");
}
#RequestMapping("/")
public String getMainMenu() {
return "main-menu";
}
}
I tried running this app on tomcat 9 through eclipse as well as manually but in both the scenarios i got same error.
Assuming the application deploys without errors (check your logs), the URI path you are using to access it is almost certainly wrong. In a servlet environment the URI path decomposes as:
<context-path><servlet-path><path-info>
where:
<context-path> is the prefix to your application. In the Eclipse server configuration page this is called just "path" and defaults to /<project-name>,
<servlet-path> is configured through the <servlet-mapping> element in your web.xml deployment descriptor,
<path-info> is the part usually used by Spring to perform its internal routing (unless alwaysUseFullPath is set on the HandlerMapping).
Therefore (theoretically) you should try accessing:
http://localhost:8080/projectName/spring-mvc-demo/
There is however another problem: your servlet mapping is an exact mapping, that does not match anything else beyond /projectName/spring-mvc-demo. You should replace it with a prefix mapping (see this question for an overview of servlet mappings):
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/spring-mvc-demo/*</url-pattern>
</servlet-mapping>
If you want to shorten your URL, the DispatcherServlet is usually mapped as default servlet /. Be aware not to use the catchall prefix mapping /*, which would override the mapping of the JSP servlet.
Remark: There are some cases when Spring does not use the part after <servlet-path> for its routing, e.g. when you use an exact or extension mapping, the whole path after <context-path> is used.
Therefore if you use:
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/spring-mvc-demo</url-pattern>
</servlet-mapping>
you should specify:
#RequestMapping("/spring-mvc-demo")
public String getMainMenu() {
...
}
and use the URL http://localhost:8080/appName/spring-mvc-demo.
When I run the web application I should see some information about the dispatcher servlet in the console but I only get information about the TomCat server. The Spring dispatcher servlet never get's loaded as it should. I've tried everything for about a week now but I still could not get it working. Here is some code.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>spring-mvc-demo</display-name>
<!-- Spring MVC Configs -->
<!-- Step 1: Configure Spring MVC Dispatcher Servlet -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Step 2: Set up URL mapping for Spring MVC Dispatcher Servlet -->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
mvc-servlet.xml
<?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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- Step 3: Add support for component scanning -->
<context:component-scan base-package="pack"/>
<!-- Step 4: Add support for conversion, formatting and validation support -->
<mvc:annotation-driven/>
<!-- Step 5: Define Spring MVC view resolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
The output in my console shows only info about TomCat:
My console output
I need to see this info message:
Correct console output
I actually found an answer, this is very very specific problem for those who are following this udemy course from love2code.com. The problem was that the instructor used some faulty jar files that worked back when he made the tutorial but do not work today. The solution is to add the spring-web and spring-webmvc dependencies to your pom.xml. This solved my silly problem. Special Thanks to Chad Darby (udemy instructor) for wasting my time with these faulty jars.
I am using spring framework 5.0.4 and tomcat server 9.0.2.
And its a maven project.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
dispatcher-servlet.xml
<?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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/cache/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven/>
<context:component-scan base-package="com.project.springbase"/>
<!-- This is the location under /webapp/resources -->
<mvc:resources mapping="/resources/**" location="/resources/" />
<!-- Can also use the default maven resources folder with subfolder name-->
<!--<mvc:resources mapping="/resources/**" location="classpath:/foo/" />-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
<!--<tx:annotation-driven transaction-manager="transactionManager"/>-->
</beans>
applicationContext.xml
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/tx/spring-context-4.0.xsd">
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/datasource-cfg.properties" />
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}" />
</beans>
Here is my intellij server console when deploying project:
And here is the browser output:
Everytime i deploy or run the project this page comes instead of my index.
And here is my home controller along with the project strcture:
With all my configurations, whenever i run the project, it shows the tomcat page on localhost:8080 instead of my project index.jsp.
What could be the possible reason?
Try this tutorial, it helped me. also change change your port number
Step 1 create Spring project on IntelliJ
Additional libraries
Spring MVC and
Java EE: Web Application
Step 2
in web.xml
- change
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.form</url-pattern>
- to
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
Step 3
Edit your dispatcher-servlet.xml
<context:component-scan base-package="com.springdemo" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
Step 4
Create your Controller.java
Step 5
Add Tomcat Server
Run > Edit Configuration > Click "+" > Tomcat Server > Local
Still inside Run/Debug Configurations dialog box
Warning: No artifacts marked for deployment > Click Fix
on Application context: "/" remove name_war_exploded
under Server I change my URL tohttp://localhost:8082/
Also on HTTP Port: 8082
Step 6
File > Project Structure > Problems (2) >
Click Fix > add all all missing dependancies
Step 7
delete index.jsp in directory web
create a new index.jsp in directory web > WEB-INF > views
In Run Configuration you have following section:
So you either need to uncheck the After Launch action or change URL to http://localhost:8080/index.jsp or whatever else.
Im trying to create my first Spring MVC project but I keep getting error http status 404.
If i try to open an .jsp file outside of /views (So not using Spring MVC) it works fine
Here are my files:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>fj21-tarefas</display-name>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-context.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
spring-context.xml
<?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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd">
<context:component-scan base-package="br.com.caelum.tarefas" />
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
Controller
package br.com.caelum.tarefas.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class OlaMundoController {
#RequestMapping("/olaMundoSpring")
public String execute(){
System.out.println("Executando a lógica com Spring MVC");
return "ok";
}
}
Libs
aopalliance-1.0.jar
commons-logging-1.2.jar
javax.servlet.jsp.jstl-1.2.1.jar
javax.servlet.jsp.jstl-api-1.2.1-3.jar
jcl-over-slf4j-1.7.12.jar
joda-time-2.4.jar
log4j-over-slf4j-1.7.12.jar
slf4j-api-1.7.12.jar
slf4j-log4j12-1.7.12.jar
spring-aop-4.1.7.RELEASE.jar
spring-aspects-4.1.7.RELEASE.jar
spring-beans-4.1.7.RELEASE.jar
spring-context-4.1.7.RELEASE.jar
spring-context-support-4.1.7.RELEASE.jar
spring-core-4.1.7.RELEASE.jar
spring-expression-4.1.7.RELEASE.jar
spring-instrument-4.1.7.RELEASE.jar
spring-instrument-tomcat-4.1.7.RELEASE.jar
spring-jdbc-4.1.7.RELEASE.jar
spring-jms-4.1.7.RELEASE.jar
spring-messaging-4.1.7.RELEASE.jar
spring-orm-4.1.7.RELEASE.jar
spring-oxm-4.1.7.RELEASE.jar
spring-test-4.1.7.RELEASE.jar
spring-tx-4.1.7.RELEASE.jar
spring-web-4.1.7.RELEASE.jar
spring-webmvc-4.1.7.RELEASE.jar
spring-webmvc-portlet-4.1.7.RELEASE.jar
spring-websocket-4.1.7.RELEASE.jar
When your controller method returns a String, the String to be returned is the name of your view (jsp, template, etc).
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
According to the setup above (provided by you), Spring in intended to return a view located on /WEB-INF/views and the name of the view must has the suffix ".jsp".
Please, make sure the file "ok.jsp" is located inside this path, otherwise, Spring will not be able to load it.
In case "ok.jsp" is already located in this folder, please, provide us full stacktrace of the exception you are facing.
Yes, the view "ok.jsp" is located on the corrected folder.
I ended up fixing the issue by deleting all the libs and adding the dependency using maven.
If you are using spring, you should us spring boot to get started with any new service. Takes care of your basic dep tree. Refer to the tutorial at - http://projects.spring.io/spring-boot/#quick-start
Pretty straight forward.
This question already has answers here:
Why does Spring MVC respond with a 404 and report "No mapping found for HTTP request with URI [...] in DispatcherServlet"?
(13 answers)
Closed 6 years ago.
I'm absolutely newbie with Java and Spring and I want to learn from example.
I'm using an out-of-the-box configuration / installation
Mac OSX
Springsource Tool Suite as IDE
Spring 2.8.1.RELEASE
vfabric-tc-server-developer-2.6.1.RELEASE
I've tried to generate a new project based on "Spring Template Project". Then I've chosen the "Spring MVC Project". The sample project is generated. After that, without modifying anything, I've tried to execute de "home.jsp" page via "Run As". The Web Server starts and finally I received the error in the console Tab.
No mapping found for HTTP request with URI [/myproject/] in
DispatcherServlet with name 'appServlet'
And this other output in these web pages:
http://localhost:8080/myproject/WEB-INF/views/home.jsp
http://localhost:8080/myproject
Here you can see an image on how my project is structured (auto generated for STS):
What is wrong?
Here you can see the content of the web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
The root-context.xml file has this content.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
</beans>
And finally the servlet-context.xml has this content.
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC #Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by #Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="com.mycompany.myapp" />
</beans:beans>
Does anybody have an idea to solve it?
Spring's convention is to assume that the <servlet-name> in the web.xml for the DispatcherServlet matches the beginning of the Spring servlet context XML file. Rename servlet-context.xml to appServlet-context.xml and see if that helps.
Everything under WEB-INF is not accessible from the outside, and the point of an MVC framework is to invoke a controller before dispatching to the view, so invoking the JSP directly should not be done anyway.
And you probably don't have any Spring controller mapped to the root URL, so obviously, there is nothing at the URL http://localhost:8080/myproject/.
Add a Controller to your application that returns a ModelAndView instance with name "home". Then configure some handler mapping to that Controller and try to access your web app with a URL similar to this one: http://localhost:8080/myproject/home.do. More information can be found here and here.