2017-01-30 9 views
0

Spring MVCを使用していくつかの残りのサービスを公開しています。私はこの方法でそれらを公開している:Google App EngineでSpring MVC Restサービスにアクセスできない

@RestController 
@RequestMapping("/testpath") 
public class ConcreteMyController implements MyController { 

    @RequestMapping(method = RequestMethod.GET) 
    @ResponseStatus(value = HttpStatus.OK) 
    @Override 
    public String testGet(@RequestBody HttpServletRequest req, HttpServletResponse resp) { 
     return "here is a string"; 
    } 
} 

はGoogle App Engine上にデプロイした後、私は404エラーを取得せずにhttps://mydomain.appspot.com/testpathにアクセスできないことに気づきます。

私はHttpServletのにそれを変更して、それは次のように働いている試みた:

public class ConcreteMyController extends HttpServlet { 

    @Override 
    public String doGet(HttpServletRequest req, HttpServletResponse resp) { 
     PrintWriter respWriter = resp.getWriter(); 
     resp.setStatus(200); 
     resp.setContentType("text/html"); 
     respWriter.println("here is a string"); 

    } 
} 

のweb.xmlは次のようになります。

<web-app> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value> 
    </context-param> 
    <filter> 
     <filter-name>CORS</filter-name> 
     <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class> 
    </filter> 
    <filter-mapping> 
     <filter-name>CORS</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 
    <servlet> 
     <servlet-name>dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value></param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 



    <servlet> 
     <servlet-name>testservlet</servlet-name> 
     <servlet-class>package.ConcreteMyController</servlet-class> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>PlusSampleServlet</servlet-name> 
     <url-pattern>/plussampleservlet</url-pattern> 
    </servlet-mapping> 

    <security-constraint> 
     <web-resource-collection> 
      <web-resource-name>any</web-resource-name> 
      <url-pattern>/anotherpathIamusing</url-pattern> 
     </web-resource-collection> 
     <auth-constraint> 
      <role-name>*</role-name> 
     </auth-constraint> 
    </security-constraint> 
</web-app> 

私のMVC-ディスパッチャ-servlet.xmlは次のようになります。

<beans xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns="http://www.springframework.org/schema/beans" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 


     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-3.2.xsd"> 

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

は、私はこのように見えるファイルを持っているコンフィグパッケージで:私はこれはGoogle App Engineプロジェクト作られた前

@EnableWebMvc 
@EnableScheduling 
@EnableTransactionManagement 
@EnableJpaRepositories("package.model.repository") 
@ComponentScan("package") 
@Configuration 
public class AppConfig { 
    //Omitted datasources 
} 

Spring MVCのコードが取り組んできました。今私はサービスを公開するためにHttpServletを使用する必要があります。 Spring MVCオプションを機能させるにはどうすればいいですか?ヘルプは非常に高く評価されます。

注:web.xmlに関しては、Spring MVCの有無にかかわらずコードを投稿しています。テスト時には、私はそれらのうちの1つだけを使用しています。

答えて

0

は、web.xmlのSpring MVCのための私のサーブレットマッピングを削除し、これに置き換え:

<servlet> 
    <servlet-name>SpringController</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>SpringController</servlet-name> 
    <url-pattern>/*</url-pattern> 
</servlet-mapping> 

それは、このような正常に動作しています。

関連する問題