[英]Spring MVC configuration
我將eclipse和Jboss用於簡單Spring MVC應用程序的編碼。 我創建了一個企業應用程序,並在application.xml中將上下文根設置為myAppWeb。
我的web.xml詳細信息:
<servlet>
<servlet-name>springapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
我的springspringapp-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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
<!-- the application context definition for the springapp DispatcherServlet -->
<bean name="/a.htm" class="com.init.servlet.test.HelloController" />
</beans>
現在,當我輸入網址為
"http://localhost:8080/myAppWeb/a.htm"
我得到和404錯誤,日志消息為:
" servlet.PageNotFound OO noHandlerFound() OO No mapping found for HTTP request with URI [/myAppWeb/a.htm] in DispatcherServlet with name 'springapp'".
我將springspringapp-servlet.xml中的配置更改為
<bean name="/myAppWeb/a.htm" class="com.init.servlet.test.HelloController" />
仍然無法正常工作。
有人可以幫我這個忙嗎?
謝謝!
對於我的項目,“ *-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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
</beans>
spring應用程序啟動時,“ web.xml”文件具有上下文偵聽器以讀取配置:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/SpringAppServlet.xml</param-value>
</context-param>
<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener </listener-class>
</listener>
然后,上下文偵聽器指向的文件('/WEB-INF/SpringAppServlet.xm')包含您的配置:
<?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-4.0.xsd">
<!-- the application context definition for the springapp DispatcherServlet -->
<bean name="/hello.htm" class="com.init.servlet.test.HelloController" />
</beans>
您需要通過將bean配置文件作為上下文參數傳遞,在web.xml中指定Context loader偵聽器,如下所示
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/SpringAppServlet.xml</param-value> </context-param>
<listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.