加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

java-Spring 3和Google App引擎的问题

发布时间:2020-12-15 01:19:14 所属栏目:大数据 来源:网络整理
导读:这是我的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"xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemaLocation="http

这是我的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"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

这是我的dispatcher-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    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
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    <!-- JSR-303 support will be detected on classpath and enabled automatically -->
    <mvc:annotation-driven/>
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="suffix" value=".jsp"/>
    </bean>
</beans>

我有一个带注释的Controller类:

@Controller
public class MainController {
    @RequestMapping("/test")
    public ModelAndView testHandler(){
          ModelAndView mav = new ModelAndView();
            mav.setViewName("testView");
            mav.addObject("message","test");
            return mav;
    }
}

该项目编译没有错误,但是当我运行它并单击http://.aggengine.com//test时,我得到一个404.我的映射错误还是URI?

最佳答案
我认为您忘记了创建< bean>为您的控制器.

<mvc:annotation-driven/>

只需启用对在创建bean时读取注释的支持即可.

例如.要注册您的控制器:

<bean id="mainController" class="my.package.MainController"/>

另外,您可以启用自动类路径扫描,但这会导致appengine变慢(这会在您的应用每次冷启动时发生)而导致性能问题.

要启用类路径扫描,请将上下文名称空间添加到您的< beans>中.并添加:

 <context:component-scan base-package="my.package"/>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读