Google app engine Bean使用@Controller初始化,但@RequestMapping不使用';我没接到电话
下面是我为新的基于Spring 3注释的控制器所做的设置: //dispatcher-servlet.xmlGoogle app engine Bean使用@Controller初始化,但@RequestMapping不使用';我没接到电话,google-app-engine,spring-mvc,controller,javabeans,applicationcontext,Google App Engine,Spring Mvc,Controller,Javabeans,Applicationcontext,下面是我为新的基于Spring 3注释的控制器所做的设置: //dispatcher-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" xmlns:p="http://www.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:security="http://www.springframework.org/schema/security"
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/tx http://www.springframework.org/schema/tx/spring-tx-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/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<!--
The index controller.
-->
<bean name="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="index" />
<!-- Enables plain controllers -->
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="order" value="1" />
<property name="ignoreAcceptHeader" value="true" />
<property name="mediaTypes">
<map>
<entry key="xml" value="application/xml" />
<entry key="json" value="application/json" />
</map>
</property>
</bean>
<!-- Entity Property binding for webBindingInitializer -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="org.opevel.web.BindingInitializer" />
</property>
</bean>
<context:component-scan base-package="org.opevel.web"/>
</beans>
当我导航到/auth时,我得到一个404。当我尝试在applicationContext
中注册bean时,如下所示:
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/auth">GoogleLoginService</prop>
</props>
</property>
<bean id="GoogleLoginService" class="org.opevel.web.LoginGoogleController" />
谷歌登录服务
我通过ControllerClassNamehandlerMapping
得到一个BeanException
声明bean已经在/logingogle
注册。我正在谷歌应用程序引擎上使用Spring3.0.2
非常感谢您的帮助。该错误告诉您在应用程序上下文中不需要
。您也不需要
@Controller为您创建一个bean,@RequestMapping创建URL映射。我从应用程序上下文文件中删除了
ControllerClassNameHandlerMapping
和SimpleUrlHandlerMapping
bean,从而解决了这个问题
我正在创建一个简单的身份验证,允许用户通过openid登录。在控制器中,我只是测试看看控制器是否准备好开始服务请求,然后我可以开始添加必要的代码。是的,我知道。我只是想看看如果我添加@Controller会发生什么。问题是,排除bean后,我仍然在/auth上得到404。您是否也需要
simplecontrollerhandleadapter
bean?这可能有冲突。我已经删除了SimpleControllerHandlerAdapter
bean。无法解决问题。是否取消注释//@RequestMapping(value=“/auth”,method=RequestMethod.GET)
package org.opevel.web;
@Controller
public class LoginGoogleController {
private static final Logger log = Logger.getLogger(LoginGoogleController.class.getName());
public LoginGoogleController() {
log.info("constructing LoginGoogleController");
}
@RequestMapping(value="/auth", method=RequestMethod.GET)
public String doGet(HttpServletRequest request, HttpServletResponse response) throws Exception {
return "redirect:index";
}
}
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/auth">GoogleLoginService</prop>
</props>
</property>
<bean id="GoogleLoginService" class="org.opevel.web.LoginGoogleController" />