Tôi hoàn toàn là người mới sử dụng Java và Spring và tôi muốn học từ ví dụ.Không tìm thấy ánh xạ nào cho yêu cầu HTTP với URI [/ myproject /] trong DispatcherServlet với tên 'appServlet'
Tôi đang sử dụng một out-of-the-box cấu hình/cài đặt
- Mac OSX
- SpringSource Tool Suite như IDE
- Xuân 2.8.1.RELEASE
- vfabric-tc -server-developer-2.6.1.RELEASE
Tôi đã cố gắng tạo một dự án mới dựa trên "Spring Template Project". Sau đó, tôi đã chọn "Spring MVC Project". Dự án mẫu được tạo ra. Sau đó, mà không sửa đổi bất cứ điều gì, tôi đã cố gắng để thực hiện de "home.jsp" trang thông qua "Run As". Máy chủ Web khởi động và cuối cùng tôi đã nhận được lỗi trong bảng điều khiển Tab.
Không có ánh xạ tìm thấy cho yêu cầu HTTP URI [/ myproject /] trong DispatcherServlet với tên 'appServlet'
Và đầu ra khác này trong các trang web:
http://localhost:8080/myproject/WEB-INF/views/home.jsp
http://localhost:8080/myproject
đây bạn có thể thấy một hình ảnh về cách dự án của tôi được cấu trúc (tự động tạo ra cho STS):
Điều gì là sai?
đây bạn có thể xem nội dung của các 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>
Các gốc context.xml tập tin có nội dung này.
<?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>
Và cuối cùng là servlet-context.xml có nội dung này.
<?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>
Có ai có ý tưởng giải quyết không?
@AlfonsoDominguez @duffymo Dự án được tạo tự động có tệp có tên "HomeController.java" với nội dung sau: ' gói com.mycompany.myapp; [...] OMITED PART [...] /** * Xử lý yêu cầu cho trang chủ ứng dụng. */ @Controller public class HomeController { \t \t \t/** \t * Đơn giản chỉ cần chọn xem nhà để render bằng cách trả lại tên của nó. \t */ \t @RequestMapping (value = "/", method = RequestMethod.GET) \t public String nhà (Locale locale, mô hình Model) { \t \t String str = "Thông báo máy chủ"; \t \t \t \t model.addAttribute ("serverTime", str); \t \t \t \t trả lại "nhà riêng"; \t} \t } ' Là những gì bạn nói? –
yep, đó là ý của tôi, bạn có cố gắng truy cập URL 'http: // localhost: 8080/myproject/home' không? URL đó có vẻ là URL chính xác từ các tệp cấu hình của bạn. –