ここに問題があります。
新しいDATAJPAリポジトリモジュール(インターフェース拡張
CrudRepository<T, ID extends Serializable>
)を使用して、Spring3.0.5を使用しています。
アプリのセキュリティソリューションとしてApacheShiro1.1.0を使用しています。Apache shiroは、Spring BeanDefintionxmlファイルで次のように構成されています。
<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>
私のアプリはスタンドアロンアプリケーションであり、このApachoeShiro構成はそれを反映していることに注意してください。
Spring JPAリポジトリの構成と標準のSpring構成(アノテーションスキャン)は他のファイルで構成されていますが、これらはこの問題に関連していないようですので、印刷をスキップします。
私SecurityDAORealm
のクラスは、クレデンシャルが格納されているデータベースにアクセスするためのCredentialsRepository
jpaリポジトリコントローラーインターフェイス( )として自動配線されています。CredentialsRepository extends CrudRepository<T, ID extends Serializable>
@Component
public class SecurityDAORealm extends AuthorizingRealm {
@Autowired
CredentialRepository credentialRepository;
...
}
今問題のために。
Apache Shiroアノテーションスキャンが設定されている場合、タイプの自動配線されたBeanがCredentialsRepository
見つからないため、配線されていません。注釈スキャンがオフになっている場合、CredentialsRepository変数は自動配線され、すべてが正しく機能します。
ApacheShiroアノテーション処理が可能な部分はこちら
<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>
その中心的な平和をコメントアウトすることによって
<!-- <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor"/> -->
アノテーションはオフになっており、コメントを外すと再びオンになります。
テストとして、の代わりに単純なpojoを自動配線しようとしましたがCredentialsRepository
、これはどちらの場合でもうまく機能します(注釈のオン/オフ)。
春の内部はあまり見ていません。ここで発生している可能性があるのは、SpringがバックエンドでCredentialsRepository
適切な実装()を作成する機会がないため、変数が自動配線されていないことです。SimpleJpaRepository
回避策は、スプリングマネージドインターフェイスの実装ではなく、「フルクラス」のJPAコントローラーを自動配線するだけです。
ただし、これが修正が必要なバグなのか、それともスプリングデータインターフェイスでも機能する可能性のある追加のスプリングマジックがここに存在するのか、興味があります。