朋友,錯誤使用Spring Security 3.0.2 X春3.0.1 - 代理無法創建
我已經失去了幾天搜索互聯網的答案關於我的問題,並沒有發現任何可能實際解決它。我嘗試了幾種不同的配置,但仍然無濟於事。
這裏是我的問題:
我有工作正常,直到我決定增加春季安全的應用程序。在我介紹這個組件後,我一直在啓動tomcat 6.0.24時收到這些消息:
INFO: Bean 'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
Mar 10, 2010 3:46:47 PM org.springframework.context.support.AbstractApplicationContext$BeanPostProcessorChecker postProcessAfterInitialization
INFO: Bean 'org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource#0' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
Mar 10, 2010 3:46:47 PM org.springframework.context.support.AbstractApplicationContext$BeanPostProcessorChecker postProcessAfterInitialization
INFO: Bean 'org.springframework.security.methodSecurityMetadataSourceAdvisor' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
Mar 10, 2010 3:46:48 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
我沒有收到。因此,現在所有類都不會獲取業務類的代理,而是獲得不提交事務的POJO。我正在使用@PersistenceContext註解並注入EntityManager,但在Spring Security出現後,我一直在獲取NPE(EntityManager不再被注入)。所以,我想延長的JpaDaoSupport和獲得EntityManager的以不同的方式,像這樣:
getJpaTemplate()
.execute(new JpaCallback() {
public Object doInJpa(final EntityManager em)
throws PersistenceException {
// Here, I get an EntityManager...
}
});
它的工作原理,因爲現在我沒有得到任何NPE了。但它仍然不是代理。
如果我註釋掉app-security.xml文件並且不加載它的bean,那麼應用程序可以正常工作。如果我這樣做,則不會創建代理,並且應用程序不會提交任何事務。
我的應用程序,security.xml文件是:
[?xml version="1.0" encoding="UTF-8"?]
[beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans 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"
]
[bean id="interfaceDecisionManagerBean" class="com.mot.br.jag.security.InterfaceDecisionManager" /]
[security:global-method-security
access-decision-manager-ref="interfaceDecisionManagerBean"
/]
[security:http auto-config="false" access-decision-manager-ref="interfaceDecisionManagerBean"]
[security:form-login login-page="/login.html"
login-processing-url="/loginProcess"
default-target-url="/index.jsp"
authentication-failure-url="/login.html?login_error=1" /]
[security:anonymous /]
[security:logout logout-url="/logout" logout-success-url="/logoutSuccess.html" /]
[security:port-mappings]
[security:port-mapping http="8080" https="8443"/]
[/security:port-mappings]
[/security:http]
[security:ldap-server
id="motoLDAP"
url="[private... ]"
/]
[security:authentication-manager]
[security:ldap-authentication-provider
server-ref="motoLDAP"
user-search-filter="(uid={0})"
user-search-base="ou=intranet"
/]
[/security:authentication-manager]
[bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource"]
[constructor-arg value="[... private ...]"/]
[/bean]
[bean id="userSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch"]
[constructor-arg index="0" value="ou=intranet"/]
[constructor-arg index="1" value="(uid={0})"/]
[constructor-arg index="2" ref="contextSource" /]
[/bean]
[bean id="ldapAuthentication" class="com.mot.br.jag.security.authentication.LDAPAuthentication"]
[constructor-arg index="0"]
[bean id="ldapProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider"]
[constructor-arg]
[bean class="org.springframework.security.ldap.authentication.BindAuthenticator"]
[constructor-arg ref="contextSource" /]
[property name="userSearch" ref="userSearch" /]
[/bean]
[/constructor-arg]
[/bean]
[/constructor-arg]
[constructor-arg index="1" ref="userSearch" /]
[/bean]
[/beans]
我的應用程序,是的persistence.xml:
[?xml version="1.0" encoding="UTF-8"?]
[beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd"]
[bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /]
[bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /]
[bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator" /]
[!-- ENTITY MANAGERS --]
[bean id="interfaceEMF"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"]
[property name="persistenceUnitName" value="interfaceDS" /]
[/bean]
[!-- TRANSACTION MANAGERS --]
[bean id="interfaceTM" class="org.springframework.orm.jpa.JpaTransactionManager"]
[property name="entityManagerFactory" ref="interfaceEMF" /]
[/bean]
[!-- TX ADVICES --]
[tx:advice id="txAdvice" transaction-manager="interfaceTM"]
[tx:attributes]
[tx:method name="*" propagation="REQUIRED" rollback-for="Throwable" /]
[/tx:attributes]
[/tx:advice]
[!-- AOP CONFIG --]
[aop:aspectj-autoproxy /]
[aop:config]
[aop:pointcut id="businessMethods" expression="execution(* com.mot.br.jag.business.Business+.*(..))" /]
[aop:advisor advice-ref="txAdvice" pointcut-ref="businessMethods" /]
[/aop:config]
[/beans]
我跑出來的想法......我讀過,這是一個錯誤,因爲bean的預處理順序發生了,但是我也讀過這個bug已經修復了。如果我沒有清楚地表達自己,我很抱歉,英語不是我的第一語言。如果能引導我朝着正確的方向發展,我會很樂意回答任何問題。 :)
非常感謝你提前, 羅德里戈
你的意思是說它曾用於春季安全2.x? –
你沒有清楚地說明問題所在。你說你正在得到一個NPE - 你能發佈這個NPE的堆棧跟蹤嗎?你還會說「如果我註釋掉app-security.xml文件並且不加載它的bean,那麼應用程序工作正常」,你需要在這裏更具體一點 - 如果你刪除整個文件,這是_really_ true,或者只是''聲明?註釋處理器可以在哪裏找到註釋?你在相同的bean上混合了@Transactional和@Secured註解嗎?請提供更多信息! –