2012-01-05 15 views
0

@Secureのアノテーションをコントローラのメソッドに追加して実行する方法は? は今、私はそれを実行しました例外のように:春のセキュリティで@secureアノテーションを追加する方法

org.springframework.beans.factory.BeanCreationException:エラー名で 'companyController' が定義されたファイル内のBeanを作成し、[C:\ワークスペースの\ STS \ SpringSourceの\のvFabric - tc-server-developer-2.6.1.RELEASE¥spring-insight-instance¥wtpwebapps¥BillingEngine¥WEB-INF¥classes¥com¥sesami¥common¥management¥web¥controller¥CompanyController.class】:Beanの初期化に失敗しました;ネストされた例外はorg.springframework.aop.framework.AopConfigExceptionです:予期しないAOP例外。ネストされた例外はorg.springframework.beans.factory.BeanCreationExceptionです: 'org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor#0'という名前のBeanを作成中にエラーが発生しました:bean 'accessDecisionManager'の設定中にbean 'accessDecisionManager'への参照を解決できません 'accessDecisionManager '; org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723) (org.apache.catalina.core)で定義されているbeanはありません。 (org.springframework.aop.framework.AopConfigException:予期しないAOP例外、ネストされた例外はorg.springframework.beans.factoryです。 BeanCreationException: 'org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor#0'という名前のBeanを作成中にエラーが発生しました:bean 'accessDecisionManager'を設定中にbean 'accessDecisionManager'への参照を解決できません。

私は「春のセキュリティの.xmlに

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsdを持っている>

<global-method-security secured-annotations="enabled"> 
<!-- 
<protect-pointcut access="ROLE_ADMIN" 
     expression="execution(* com.sesami.common.management.web.controller.AdminController.*(..))" /> 
     --> 
</global-method-security> 

<!-- URL pattern based security --> 
<http auto-config="false" entry-point-ref="authenticationEntryPoint" 
    use-expressions="true"> 
    <custom-filter ref="authenticationFilter" position="FORM_LOGIN_FILTER" /> 
    <intercept-url access="hasRole('ROLE_ADMIN')" pattern="/common/admin/**" /> 
    <intercept-url pattern="/common/accounting/**" access="hasRole('ROLE_USER')" /> 
    <intercept-url pattern="/common/billing/**" access="hasRole('ROLE_COMPANY')" /> 
    <logout logout-success-url="/" logout-url="/logout"/> 

</http>......... 

コントローラには、次のように追加します。

@Secure("ROLE_ADMIN") 
@RequestMapping(value = "/common/admin/addAdmin", method = RequestMethod.GET) 
    public String add(ModelMap map) { 
     map.addAttribute(new Administrator()); 
     return "/common/admin/addAdmin"; 
    } 

いくつかのクラスを設定またはインポートする必要がありますか?

答えて

1
Cannot resolve reference to bean 'accessDecisionManager' while setting bean property 'accessDecisionManager'; nested exception is 
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'accessDecisionManager' is defined 

春はあなたのためのデフォルトのaccessDecisionManagerを作成する必要がありますが、それはおそらくいくつかの設定の問題には、起きていないように見えます。ちょうどあなたのHTTP設定でauto-configをtrueに設定すると何が起きるのでしょうか?

0
<bean id="accessDecisionManager" class="org.springframework.security.access.vote.UnanimousBased" xmlns="http://www.springframework.org/schema/beans"> 
    <constructor-arg> 
     <list> 
      <bean class="org.springframework.security.oauth2.provider.vote.ScopeVoter" /> 
      <bean class="org.springframework.security.access.vote.RoleVoter" /> 
      <bean class="org.springframework.security.access.vote.AuthenticatedVoter" /> 
     </list> 
    </constructor-arg> 
</bean> 

このBeanを定義する必要があります。

関連する問題