2016-07-16 4 views
1

アイブ氏のセットアップに春4を使用して簡単なREST APIを返す春REST常に春のセキュリティと404が見つかりませんでした

web.xmlの

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/mysabisabi-servlet.xml, 
    classpath*:META-INF/spring/applicationContext.xml, 
     classpath*:META-INF/spring/mysabisabi-security.xml 
    </param-value> 
</context-param> 
<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 
<servlet> 
    <servlet-name>mysabisabi-rest</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>mysabisabi-rest</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

AccountController.java

@RestController 
@RequestMapping(value="/api") 
public class AccountController { 


    @RequestMapping(value="/update", method=RequestMethod.POST) 
public ResponseEntity<GenericResponse> updateRegistrationToken(@RequestBody RegistrationToken token){ 
    GenericResponse response = new GenericResponse(); 
    //some code here 

    return new ResponseEntity<GenericResponse>(response, HttpStatus.ACCEPTED); 
} 

} 

mysabisabi-servlet.xml

<bean id="jacksonObjectMapper" class="com.mysabisabi.mapper.JsonCustomMapper" /> 

<bean id="jackson2HttpMessageConverter" 
    class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> 
    <property name="objectMapper" ref="jacksonObjectMapper" /> 
</bean> 

<mvc:annotation-driven> 
    <mvc:message-converters register-defaults="true"> 
     <ref bean="jackson2HttpMessageConverter" /> 
    </mvc:message-converters> 
</mvc:annotation-driven> 

mysabisabi-のsecurity.xml

<http pattern="/oauth/token" create-session="stateless" authentication-manager-ref="clientAuthenticationManager" 
    xmlns="http://www.springframework.org/schema/security"> 
<intercept-url pattern="/oauth/token" access="isFullyAuthenticated()"/> 
<csrf disabled="true"/> 
<anonymous enabled="false"/> 
<http-basic entry-point-ref="clientAuthenticationEntryPoint"/> 
<!-- include this only if you need to authenticate clients via request parameters --> 
<custom-filter ref="clientCredentialsTokenEndpointFilter" after="BASIC_AUTH_FILTER"/> 
<access-denied-handler ref="oauthAccessDeniedHandler"/> 
</http> 

    <http pattern="/api/*" create-session="never" entry-point-ref="oauthAuthenticationEntryPoint" 
    access-decision-manager-ref="accessDecisionManager" xmlns="http://www.springframework.org/schema/security"> 
<anonymous enabled="false"/> 
<csrf disabled="true"/> 
<intercept-url pattern="/api/*" access="hasRole('ROLE_USER')"/> 
<custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER"/> 
<access-denied-handler ref="oauthAccessDeniedHandler"/> 

applicationContext.xmlを

<mvc:annotation-driven /> 

<context:annotation-config /> 

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

<context:property-placeholder location="classpath:mysabisabi.properties" /> 

<tx:annotation-driven transaction-manager="transactionManager" /> 


//dataSource configuration 

ログファイル

2016-07-16 16:24:45 INFO RequestMappingHandlerMapping:537 - Mapped "{[/api/update],methods=[POST]}" onto public org.springframework.http.ResponseEntity<com.mysabisabi.dto.response.GenericResponse> com.mysabisabi.controller.AccountController.updateRegistrationToken(com.mysabisabi.dto.request.RegistrationToken) 

私はhttp://localhost:8080/mysabisabi/api/updateにアクセスしようとしたとき、私は私がURLパターンが、それでも同じよう//*の両方を試してみたHTTPStatus 404 Not Found - The requested resource is not available

を得ました。

誰かが私が見逃したことを指摘できますか?

ありがとうございました。

+0

どのフォーマットでは(JSON/XML /プレーンテキストをコントローラにあなたのリクエスト送信)? – Vaibs

+0

私はjsonを使用しています。 – blitzen12

+0

あなたのspring config xmlファイルはどこですか?あなたは設定のためにクラスファイルを使用しています。クラスファイルを共有します。 – Vaibs

答えて

0

あなたの設定は正常です。 web.xmlで以下のコードを変更してください。

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

また、以下のURLを確認してください。 Order of loading contextConfigLocation in web.xml of Spring Servlet project

1

アプリケーションコンテナは何ですか?

のTomcat、例えば、のように、文句を言わないのGoogle App Engineの一方で、http://localhost:8080/mysabisabi/api/updateのように、リンクにアプリ名を追加します。http://localhost:8080/api/update

関連する問題