我正在将依赖项从2.5.6版本的遗留spring项目更新到4.1.6版本。在工作时,我可能会尝试升级到最新的spring4版本(我知道spring4并没有给spring4.x提供更多的维护,但是我们必须在j7上解决一些其他问题)。
所以项目是Spring2.5.6,完全配置了web.xml(只是一些@autowired之类的东西)。它使用aop、springsecurity2.0.5和hibernate3.3.1,工作正常。
我已经能够更新依赖项,现在项目可以在tomcat7中很好地编译、构建和部署。除了 Spring 保安。
这就是我面临的错误
[WARN] Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#0' while setting bean property 'sourceList' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#0': Cannot resolve reference to bean 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' while setting constructor argument with key [4]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0': Cannot resolve reference to bean 'org.springframework.security.authentication.ProviderManager#0' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot create inner bean '(inner bean)#e2508ff' of type [org.springframework.beans.factory.config.MethodInvokingFactoryBean] while setting bean property 'eraseCredentialsAfterAuthentication'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#e2508ff': Invocation of init method failed; nested exception is java.lang.NoSuchMethodException: com.sun.proxy.$Proxy168.isEraseCredentialsAfterAuthentication():
java.lang.NoSuchMethodException: com.sun.proxy.$Proxy168.isEraseCredentialsAfterAuthentication()
at java.lang.Class.getMethod(Class.java:1670)
at org.springframework.util.MethodInvoker.prepare(MethodInvoker.java:174)
at org.springframework.beans.factory.config.MethodInvokingFactoryBean.afterPropertiesSet(MethodInvokingFactoryBean.java:103)
我在这里读到(所以)有人显然面临着同样的问题,这与aop有关。这里是我的相关application-context.xml配置,您可以看到我没有太宽松的切入点问题(或者至少我是这么认为的)。
<context:component-scan base-package="com.company.my.project" />
<context:annotation-config />
<!--Hibernate and JPA-->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" lazy-init="true">
<property name="persistenceXmlLocation" value="classpath:${env}/META-INF/persistence.xml"/>
<property name="dataSource" ref="dataSource" />
</bean>
<import resource="applicationContext-Manager.xml" />
<import resource="applicationContext-DAO.xml" />
<import resource="applicationContext-common-resources.xml" />
<import resource="applicationContext-Business.xml" />
<!--works without this line-->
<import resource="applicationContext-security.xml" />
<import resource="applicationContext-RestBeans.xml" />
<import resource="applicationContext-RestClient.xml" />
<import resource="applicationContext-reports.xml" />
<import resource="applicationContext-dispatcherServletBeans.xml" />
<import resource="applicationContext-Quartz.xml" />
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" lazy-init="true"/>
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" lazy-init="true"/>
<bean id="myTxManager" class="org.springframework.orm.jpa.JpaTransactionManager" lazy-init="true">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="myTxManager">
<tx:attributes>
<tx:method name="get*,count*" read-only="true" />
<tx:method name="*"
rollback-for="com.company.my.project.commons.exception.MyException" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="myPointCut"
expression="execution( com.company.my.project.server.spring.manager..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="myPointCut" />
</aop:config>
这是我完整的spring安全配置文件(为了尽量简化它,我将使用一个定制的身份验证提供程序来获取错误的来源)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
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.xsd"><sec:http auto-config="true" />
<sec:authentication-manager >
<sec:authentication-provider>
<sec:user-service>
<sec:user name="bill" password="abc123" authorities="ROLE_USER" />
<sec:user name="admin" password="root123" authorities="ROLE_ADMIN" />
<sec:user name="dba" password="root123" authorities="ROLE_ADMIN,ROLE_DBA" />
</sec:user-service>
</sec:authentication-provider>
</sec:authentication-manager>
</beans>
有人能给我一些线索吗?我已经三天没有面对这个问题了,我完全被困在这一点上:(
编辑:添加pom.xml
<springVersion>4.1.6.RELEASE</springVersion>
<springSecurityVersion>4.0.2.RELEASE</springSecurityVersion>
<slf4jVersion>1.5.2</slf4jVersion>
<jersey.version>1.18.1</jersey.version>
<jackson.mapper.version>1.9.2</jackson.mapper.version>
<jUnit.version>4.5</jUnit.version>
<activemq-spring.version>5.13.0</activemq-spring.version>
<hibernate.version>3.3.1.GA</hibernate.version>
<hibernate.annotations.version>3.4.0.GA</hibernate.annotations.version>
<!-- Spring security-->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>${springSecurityVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${springSecurityVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${springSecurityVersion}</version>
</dependency>
<!-- SLF4J -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4jVersion}</version>
<type>jar</type>
<scope>compile</scope>
<optional>false</optional>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${springVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${springVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${springVersion}</version>
<type>jar</type>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${springVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${springVersion}</version>
</dependency>
<!-- Jackson -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${jackson.mapper.version}</version>
</dependency>
<!--Active MQ-->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-spring</artifactId>
<version>${activemq-spring.version}</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
<type>jar</type>
<scope>compile</scope>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.annotations.version}</version>
<type>jar</type>
<scope>compile</scope>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>${hibernate.annotations.version}</version>
<type>jar</type>
<scope>compile</scope>
<optional>false</optional>
</dependency>
<!-- Jersey -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>${jersey.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>${jersey.version}</version>
</dependency>
编辑:添加了fullstrackce(这里,由于charlimit无法粘贴到这里)和mvn dependency:tree
[INFO] Scanning for projects...
[WARNING] The project com.company:my_project:war:5.4.0 uses prerequisites which is only intended for maven-plugin projects but not for non maven-plugin projects. For such purposes you should use the maven-enforcer-plugin. See https://maven.apache.org/enforcer/enforcer-rules/requireMavenVersion.html
[INFO]
[INFO] ---------------------< com.company:my_project>----------------------
[INFO] Building my_project5.4.0
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ my_project---
[INFO] com.company:my_project:war:5.4.0
[INFO] +- javax.persistence:persistence-api:jar:1.0.2:compile
[INFO] +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] +- junit:junit:jar:4.4:compile
[INFO] +- com.thoughtworks.xstream:xstream:jar:1.3.1:compile
[INFO] | \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] +- cglib:cglib-nodep:jar:3.1:compile
[INFO] +- org.aspectj:aspectjrt:jar:1.6.0:compile
[INFO] +- org.aspectj:aspectjweaver:jar:1.6.0:compile
[INFO] +- log4j:log4j:jar:1.2.14:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.5.2:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.5.2:compile
[INFO] +- javax.transaction:jta:jar:1.1:compile
[INFO] +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] +- org.hibernate:hibernate-annotations:jar:3.4.0.GA:compile
[INFO] | +- org.hibernate:ejb3-persistence:jar:1.0.2.GA:compile
[INFO] | +- org.hibernate:hibernate-commons-annotations:jar:3.1.0.GA:compile
[INFO] | \- org.hibernate:hibernate-core:jar:3.3.0.SP1:compile
[INFO] | \- antlr:antlr:jar:2.7.6:compile
[INFO] +- org.springframework:spring-context-support:jar:4.1.6.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:4.1.6.RELEASE:compile
[INFO] +- org.springframework:spring-beans:jar:4.1.6.RELEASE:compile
[INFO] +- org.springframework:spring-core:jar:4.1.6.RELEASE:compile
[INFO] | \- commons-logging:commons-logging:jar:1.2:compile
[INFO] +- org.springframework:spring-jms:jar:4.1.6.RELEASE:compile
[INFO] | +- org.springframework:spring-messaging:jar:4.1.6.RELEASE:compile
[INFO] | \- org.springframework:spring-tx:jar:4.1.6.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:4.1.6.RELEASE:compile
[INFO] +- org.springframework:spring-jdbc:jar:4.1.6.RELEASE:compile
[INFO] +- org.springframework:spring-orm:jar:4.1.6.RELEASE:compile
[INFO] +- org.springframework:spring-web:jar:4.1.6.RELEASE:compile
[INFO] +- org.springframework:spring-expression:jar:4.1.6.RELEASE:compile
[INFO] +- org.springframework:spring-instrument:jar:4.1.6.RELEASE:compile
[INFO] +- org.springframework:spring-instrument-tomcat:jar:4.1.6.RELEASE:compile
[INFO] +- javax.jms:jms:jar:1.1:compile
[INFO] +- com.extjs:gxt:jar:2.3.0-gwt22:compile
[INFO] +- com.company:commons_dependencies:jar:4.3.0:compile
[INFO] | +- com.company.projects:projects-clients:jar:1.0.3:compile
[INFO] | | +- org.quartz-scheduler:quartz:jar:2.1.5:compile
[INFO] | | | \- c3p0:c3p0:jar:0.9.1.1:compile
[INFO] | | +- com.company.projects.status:status-api:jar:1.0.1:compile
[INFO] | | | +- org.apache.log4j:com.springsource.org.apache.log4j:jar:1.2.15:compile
[INFO] | | | \- com.sun.mail:javax.mail:jar:1.4.5:compile
[INFO] | | +- commons-net:commons-net:jar:3.3:compile
[INFO] | | +- org.apache.commons:commons-text:jar:1.2:compile
[INFO] | | | \- org.apache.commons:commons-lang3:jar:3.7:compile
[INFO] | | +- net.spy:spymemcached:jar:2.12.3:compile
[INFO] | | +- de.oscillation.gwt:goda-time:jar:0.0.1:compile
[INFO] | | +- org.codehaus.sonar-plugins:sonar-ant-task:jar:2.1:compile
[INFO] | | +- net.bull.javamelody:javamelody-core:jar:1.81.0:compile
[INFO] | | | \- org.jrobin:jrobin:jar:1.5.9:compile
[INFO] | | +- org.jasypt:jasypt-springsecurity3:jar:1.9.0:compile
[INFO] | | +- com.google.code.gson:gson:jar:2.2.2:compile
[INFO] | | +- org.apache.activemq:activemq-all:jar:5.3.1:compile
[INFO] | | +- org.jvnet:mimepull:jar:1.6:compile
[INFO] | | +- joda-time:joda-time:jar:2.1:compile
[INFO] | | \- com.google.zxing:core:jar:3.1.0:compile
[INFO] | +- org.hibernate:hibernate-entitymanager:jar:3.4.0.GA:compile
[INFO] | | \- javassist:javassist:jar:3.4.GA:compile
[INFO] | +- com.google.gwt:gwt-user:jar:2.4.0:compile
[INFO] | | +- javax.validation:validation-api:jar:1.0.0.GA:compile
[INFO] | | \- javax.validation:validation-api:jar:sources:1.0.0.GA:compile
[INFO] | +- com.google.gwt:gwt-servlet:jar:2.4.0:compile
[INFO] | +- net.sf.ehcache:ehcache:jar:1.6.1:compile
[INFO] | +- org.slf4j:jcl-over-slf4j:jar:1.5.2:runtime
[INFO] | +- com.google.code.gwt-log:gwt-log:jar:2.5.2:compile
[INFO] | +- javax.mail:mail:jar:1.4:compile
[INFO] | | \- javax.activation:activation:jar:1.1:compile
[INFO] | +- org.springframework.security:spring-security-core:jar:4.0.2.RELEASE:compile
[INFO] | | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] | +- org.springframework.security:spring-security-web:jar:4.0.2.RELEASE:compile
[INFO] | +- org.springframework.security:spring-security-config:jar:4.0.2.RELEASE:compile
[INFO] | +- org.apache.activemq:activemq-spring:jar:5.13.0:compile
[INFO] | | +- org.apache.xbean:xbean-spring:jar:3.18:compile
[INFO] | | +- org.apache.activemq:activemq-broker:jar:5.13.0:compile
[INFO] | | | +- org.apache.activemq:activemq-client:jar:5.13.0:compile
[INFO] | | | | +- org.apache.geronimo.specs:geronimo-jms_1.1_spec:jar:1.1.1:compile
[INFO] | | | | +- org.fusesource.hawtbuf:hawtbuf:jar:1.11:compile
[INFO] | | | | \- org.apache.geronimo.specs:geronimo-j2ee-management_1.1_spec:jar:1.0.1:compile
[INFO] | | | \- org.apache.activemq:activemq-openwire-legacy:jar:5.13.0:compile
[INFO] | | +- org.apache.activemq:activemq-pool:jar:5.13.0:compile
[INFO] | | | \- org.apache.activemq:activemq-jms-pool:jar:5.13.0:compile
[INFO] | | +- org.apache.geronimo.specs:geronimo-jta_1.0.1B_spec:jar:1.0.1:compile
[INFO] | | \- org.apache.commons:commons-pool2:jar:2.4.2:compile
[INFO] | +- org.springframework:spring-test:jar:4.1.6.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:4.1.6.RELEASE:compile
[INFO] | \- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.2:compile
[INFO] +- com.googlecode:hibernate-memcached:jar:1.3:compile
[INFO] +- commons-beanutils:commons-beanutils:jar:1.8.1:compile
[INFO] +- opensymphony:ognl:jar:2.6.11:compile
[INFO] +- commons-lang:commons-lang:jar:2.3:compile
[INFO] +- commons-dbcp:commons-dbcp:jar:1.2.2:compile
[INFO] | \- commons-pool:commons-pool:jar:1.3:compile
[INFO] +- org.drools:drools-compiler:jar:5.1.0.M1:compile
[INFO] | +- org.drools:drools-core:jar:5.1.0.M1:compile
[INFO] | | \- org.drools:drools-api:jar:5.1.0.M1:compile
[INFO] | +- org.antlr:antlr-runtime:jar:3.1.1:compile
[INFO] | +- org.eclipse.jdt:core:jar:3.4.2.v_883_R34x:compile
[INFO] | +- janino:janino:jar:2.5.15:compile
[INFO] | \- org.mvel:mvel2:jar:2.0.12:compile
[INFO] +- org.apache.commons:commons-math:jar:2.0:compile
[INFO] +- com.sun.jersey:jersey-server:jar:1.18.1:compile
[INFO] | \- com.sun.jersey:jersey-core:jar:1.18.1:compile
[INFO] +- com.sun.jersey:jersey-json:jar:1.18.1:compile
[INFO] | +- org.codehaus.jettison:jettison:jar:1.1:compile
[INFO] | +- com.sun.xml.bind:jaxb-impl:jar:2.2.3-1:compile
[INFO] | | \- javax.xml.bind:jaxb-api:jar:2.2.2:compile
[INFO] | | \- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] | +- org.codehaus.jackson:jackson-core-asl:jar:1.9.2:compile
[INFO] | +- org.codehaus.jackson:jackson-jaxrs:jar:1.9.2:compile
[INFO] | \- org.codehaus.jackson:jackson-xc:jar:1.9.2:compile
[INFO] +- com.sun.jersey:jersey-client:jar:1.18.1:compile
[INFO] +- com.sun.jersey:jersey-servlet:jar:1.18.1:compile
[INFO] +- com.sun.jersey.contribs:jersey-multipart:jar:1.18.1:compile
[INFO] | \- org.jvnet.mimepull:mimepull:jar:1.9.3:compile
[INFO] +- commons-fileupload:commons-fileupload:jar:1.2.1:compile
[INFO] +- org.apache.commons:commons-io:jar:1.3.2:compile
[INFO] +- org.jasypt:jasypt:jar:1.5:compile
[INFO] | \- commons-codec:commons-codec:jar:1.1:compile
[INFO] +- com.ibm.icu:icu4j:jar:3.4.4:compile
[INFO] +- org.codehaus.groovy:groovy-all:jar:1.5.5:compile
[INFO] | +- org.apache.ant:ant:jar:1.7.0:compile
[INFO] | +- org.apache.ant:ant-launcher:jar:1.7.0:compile
[INFO] | \- jline:jline:jar:0.9.94:compile
[INFO] +- net.sf.jasperreports:jasperreports:jar:4.1.2:compile
[INFO] | +- commons-collections:commons-collections:jar:2.1:compile
[INFO] | +- commons-digester:commons-digester:jar:1.7:compile
[INFO] | +- com.lowagie:itext:jar:2.1.7:compile
[INFO] | | +- bouncycastle:bcmail-jdk14:jar:138:compile
[INFO] | | +- bouncycastle:bcprov-jdk14:jar:138:compile
[INFO] | | \- org.bouncycastle:bctsp-jdk14:jar:1.38:compile
[INFO] | | +- org.bouncycastle:bcprov-jdk14:jar:1.38:compile
[INFO] | | \- org.bouncycastle:bcmail-jdk14:jar:1.38:compile
[INFO] | +- jfree:jcommon:jar:1.0.15:compile
[INFO] | +- jfree:jfreechart:jar:1.0.12:compile
[INFO] | +- eclipse:jdtcore:jar:3.1.0:compile
[INFO] | \- org.codehaus.castor:castor:jar:1.2:compile
[INFO] +- ar.com.fdvs:DynamicJasper:jar:4.0.0:compile
[INFO] +- org.apache.poi:poi:jar:3.6:compile
[INFO] +- org.apache.poi:poi-ooxml:jar:3.6:compile
[INFO] \- org.apache.poi:poi-ooxml-schemas:jar:3.6:compile
[INFO] +- org.apache.xmlbeans:xmlbeans:jar:2.3.0:compile
[INFO] | \- stax:stax-api:jar:1.0.1:compile
[INFO] \- org.apache.geronimo.specs:geronimo-stax-api_1.0_spec:jar:1.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.790 s
[INFO] Finished at: 2021-02-16T10:29:12+01:00
[INFO] ------------------------------------------------------------------------
暂无答案!
目前还没有任何答案,快来回答吧!