好时光。
我正在尝试集成Spring MVC和Apache Tiles。问题是^当我点击我需要的网址时,“404 Not Found”会引发。以下是我的设置:
的web.xml
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
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_2_4.xsd">
<display-name>Administration Panel</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>
tiles.xml
<tiles-definitions>
<definition name="layout" template="/WEB-INF/jsp/templates/layout.jsp">
<put-attribute name="title" value=""/>
<put-attribute name="header" value="layout.header"/>
<put-attribute name="navigator" value="layout.navigator"/>
<put-attribute name="body" value=""/>
<put-attribute name="footer" value="layout.footer"/>
</definition>
<!-- The header template -->
<definition name="layout.header" template="/WEB-INF/jsp/templates/header.jsp">
<put-attribute name="header.left" value="/WEB-INF/jsp/themes/basic/header/layout_header_left.jsp"/>
<put-attribute name="header.center" value="/WEB-INF/jsp/themes/basic/header/layout_header_center.jsp"/>
<put-attribute name="header.right" value="/WEB-INF/jsp/themes/basic/header/layout_header_right.jsp"/>
</definition>
<!-- The navigator template -->
<definition name="layout.navigator" template="/WEB-INF/jsp/templates/navigator.jsp">
<put-attribute name="navigator.top" value="/WEB-INF/jsp/themes/basic/navigator/layout_navigator_top.jsp"/>
<put-attribute name="navigator.bottom" value="/WEB-INF/jsp/themes/basic/navigator/layout_navigator_bottom.jsp"/>
</definition>
<!-- The footer template -->
<definition name="layout.footer" template="/WEB-INF/jsp/templates/footer.jsp">
<put-attribute name="footer.left" value="/WEB-INF/jsp/themes/basic/footer/layout_footer_left.jsp"/>
<put-attribute name="footer.center" value="/WEB-INF/jsp/themes/basic/footer/layout_footer_center.jsp"/>
<put-attribute name="footer.right" value="/WEB-INF/jsp/themes/basic/footer/layout_footer_right.jsp"/>
</definition>
<definition name="blank" extends="layout">
<put-attribute name="body" value="/WEB-INF/jsp/themes/basic/body/layout_body.jsp"/>
</definition>
</tiles-definitions>
MVC-调度-servlet.xml中
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<context:component-scan base-package="xxx.xxx" />
<context:annotation-config/>
<mvc:annotation-driven />
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>
</beans>
控制器
@Controller
@RequestMapping("/base_page")
public class BasePageController {
@RequestMapping("/blank")
public ModelAndView getBasePage(HttpServletRequest request, HttpServletResponse response) {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("blank");
return modelAndView;
}
}
请求的网址是:http://localhost:8080/base_page/blank
(tomcat 7)
有人可以提出解决方案吗?
答案 0 :(得分:0)
谢谢Xaerxess和axtavt!
正如有争议的那样,通过将/*
更改为/admin/*
来解决问题。
现在的问题是,当xxx-servlet.xml已经存在时,Spring正在寻找applicationContext.xml?在applicationContext.xml中需要放置什么类型的bean(而不是在其他弹簧配置文件中)?