ここに問題があります。SpringデータJPAリポジトリが見つからないApache Shiroアノテーションがスプリングで有効になっている場合
私は、新しいDATA JPAリポジトリモジュール( CrudRepository<T, ID extends Serializable>
を拡張するインターフェイス)を使用して、3.0.5のスプリングを使用しています。
私はApache Shiro 1.1.0を私のアプリケーションのセキュリティソリューションとして使用しています。
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
<!-- Enable Shiro Annotations for Spring-configured beans. Only run after -->
<!-- the lifecycleBeanProcessor has run: -->
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor"/>
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager"/>
</bean>
<!-- Define the realm you want to use to connect to your back-end security datasource: -->
<bean id="securityDAORealm" class="com.bilto.archiweb.security.SecurityDAORealm" />
<bean id="securityManager" class="org.apache.shiro.mgt.DefaultSecurityManager">
<!-- Single realm app. If you have multiple realms, use the 'realms' property instead. -->
<property name="realm" ref="securityDAORealm"/>
</bean>
<!-- For simplest integration, so that all SecurityUtils.* methods work in all cases, -->
<!-- make the securityManager bean a static singleton. DO NOT do this in web -->
<!-- applications - see the 'Web Applications' section below instead. -->
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="staticMethod" value="org.apache.shiro.SecurityUtils.setSecurityManager"/>
<property name="arguments" ref="securityManager"/>
</bean>
私のアプリは、スタンドアロンのアプリケーションであり、このApachoe史郎構成はそれを反映していることに注意してください:次のようにApacheの四郎は、春の豆defintion xmlファイルに を設定されています。
標準のスプリング構成(注釈スキャン)と同様に、スプリングjpaリポジトリの構成は、他のファイルで構成されているため、この問題には関係していないと思われます。
私のSecurityDAORealm
クラスは、資格情報が保存されているデータベースにアクセスするためのjpaリポジトリコントローラインターフェイス(CredentialsRepository extends CrudRepository<T, ID extends Serializable>
)として、CredentialsRepository
をautowiringしています。
@Component
public class SecurityDAORealm extends AuthorizingRealm {
@Autowired
CredentialRepository credentialRepository;
...
}
問題が発生しました。
Apache Shiro注釈スキャンが設定されている場合、タイプCredentialsRepository
の自動受注のBeanが見つからないため、配線されません。注釈スキャンがオフになっていると、CredentialsRepository変数は自動で実行され、すべて正常に動作します。 Apacheの史郎の注釈処理をanables
一部は
<!-- <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor"/> -->
注釈が、それはそれらを再びオンにしますコメントを外し、オフにされ、その中心の平和をコメントアウトすることで、この
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
<!-- Enable Shiro Annotations for Spring-configured beans. Only run after -->
<!-- the lifecycleBeanProcessor has run: -->
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor"/>
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager"/>
</bean>
です。
私はCredentialsRepository
の代わりにシンプルなpojoを自動配線しようとしましたが、これは両方のケース(アノテーションのオン/オフ)でうまくいきます。
私は春の内部をあまり見ません。ここで起こっていることは、Springがバックエンドに適切な実装(SimpleJpaRepository
)を作成する機会を得られないため、CredentialsRepository
変数が自動配線されていないことです。
バグ管理されたインターフェイスの実装ではなく、「フルクラス」のJPAコントローラを自動配線するだけで回避できます。
しかし、これは修正が必要なバグか、スプリングデータインターフェイスでも動作させることができる追加のスプリングマジックが存在するかどうか不思議です。
+1を取る前に、史郎がinstantiantedなっていることです。ありがとう – Justin
+1助けて! – sunny
私はshiroをアプリケーションに統合しているので、これはセキュリティモジュールのために働いていました。今度は '
sunny