Google App Engine Java Production上的404错误

时间:2014-09-04 07:33:02

标签: java spring google-app-engine spring-mvc

我过去3年一直在使用Google App Engine,但之前从未遇到任何此类问题。我使用Spring-4和Objectify创建了一个项目。

我面临的问题是,本地所有网址都运行良好,但当我将其部署到appspot时,我在需要返回JSP页面的URL上遇到404错误,尽管应返回JSON或XML响应的URL,这些URL工作正常。

Appengine日志也没有提供任何相关信息。我无法理解一件事,如果它在本地运行良好,为什么它不能用于appspot

以下是我的配置文件。

应用服务引擎-web.xml中

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>swissinfos</application>
  <version>2</version>

  <threadsafe>true</threadsafe>

  <system-properties>
    <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
  </system-properties>

  <sessions-enabled>true</sessions-enabled>
</appengine-web-app>

的applicationContext.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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-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">

<!-- Activates various annotations to be detected in bean classes -->
<context:annotation-config />

<!-- Scans the classpath for annotated components that will be auto-registered as Spring beans.
 For example @Controller and @Service. Make sure to set the correct base-package-->
<context:component-scan base-package="com.lumin.mytalk." />

<!-- Configures the annotation-driven Spring MVC Controller programming model.
Note that, with Spring 3.0, this tag works in Servlet MVC only!  -->
<mvc:annotation-driven /> 

<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang"></property>
</bean>
</mvc:interceptors>


<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
    <value>WEB-INF/common.properties</value>
</list>
</property>
</bean>

<bean id="converter" class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<list>
<bean class="com.lumin.mytalk.common.util.DozerConverter">
    <property name="mapper">
    <bean class="org.dozer.spring.DozerBeanMapperFactoryBean">
    <property name="mappingFiles">
        <value>/WEB-INF/classes/dozer/dozer-bean-mappings.xml</value>
    </property>
   </bean>
</property>
</bean>
</list>
</property>
</bean>
</beans>

弹簧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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">

<context:component-scan base-package="com.lumin.mytalk." />

<!-- Application Message Bundle -->
<bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" id="messageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>

<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="en" />
</bean>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/WEB-INF/jsp/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>
</beans>

的web.xml

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">

<filter>
    <filter-name>ObjectifyFilter</filter-name>
    <filter-class>com.googlecode.objectify.ObjectifyFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>ObjectifyFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy
    </filter-class>
</filter>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/spring-security.xml
        /WEB-INF/applicationContext.xml
    </param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<error-page>
    <error-code>404</error-code>
    <location>/jsp/error.jsp</location>
</error-page>

<welcome-file-list>
    <welcome-file>jsp/index.jsp</welcome-file>
</welcome-file-list>
<servlet>
    <servlet-name>SystemServiceServlet</servlet-name>
    <servlet-class>com.google.api.server.spi.SystemServiceServlet
    </servlet-class>
    <init-param>
        <param-name>services</param-name>
        <param-value/>
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>SystemServiceServlet</servlet-name>
    <url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>
</web-app>

API控制器示例

@Controller
public class CategoryController extends AbstractGenericController{

@Autowired
private CategoryService categoryService;    

@ResponseBody
@RequestMapping(value = Path.Url.API + Path.Url.CATEGORY + Path.OperationUrl.CREATE, method = RequestMethod.POST, produces = {"application/json", "application/xml" })
public Object create(@RequestBody Category category) {
    Category isExisting = categoryService.getCategoryByName(category.getCategoryName());
    if (isExisting == null) {
        Long id = categoryService.createWithID(category);
        return new Response(null, STATUS.SUCCESS, "Category created successfully. Id :" + id);
    }else{
        return new Response(null, STATUS.FAILURE, "Category already exist. Please use update category function.");
    }
 }
}

网络控制器示例

@Controller
public class LoginLogoutController {

@RequestMapping(value = Path.Url.LOGIN)
public String loginPage(@RequestParam(value = "error", required = false) boolean error, @RequestParam(value = "maidID", required = false) String maidID, ModelMap map) {
    if (error == true) {
        map.put("error", "You have entered an invalid username or password!");
    }if( maidID != null && !maidID.equals("")){
        map.addAttribute("maidID", maidID);
    }
    if((error == true) && (maidID != null && !maidID.equals(""))){
        map.put("error", "You have entered an invalid username or password!");
        map.addAttribute("maidID", maidID);
    }
    return Path.Jsp.LOGIN_PAGE;
 }
}

GAE日志条目

  

2014-09-04 13:08:27.302 / 404 44ms 0kb Mozilla / 5.0(Windows NT 6.1; rv:35.0)Gecko / 20100101 Firefox / 35.0模块=默认版本= ​​2   123.63.241.35 - - [04 / Sep / 2014:00:38:27 -0700]“GET / HTTP / 1.1”404 256 - “Mozilla / 5.0(Windows NT 6.1; rv:35.0)Gecko / 20100101 Firefox / 35.0” “swissinfos.appspot.com”ms = 44 cpu_ms = 87 cpm_usd = 0.000029 app_engine_release = 1.9.10 instance = 00c61b117c9c5e35c6e16583e442bfebd62dc8f0

0 个答案:

没有答案