0

美好时光。

我正在尝试集成 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>

瓷砖.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)

有人可以提出解决方案吗?

4

1 回答 1

0

Thanks Xaerxess and axtavt!

The problem is solved, as axtavt pointed, by changing /* to /admin/*.

Now the question is why Spring is looking for the applicationContext.xml when the xxx-servlet.xml is already here? And what type of beans are required to be placed in the applicationContext.xml (not in other spring configuration files)?

于 2012-09-18T09:20:31.343 回答