我使用Spring Security 3和Tomcat 7.我的HTTP標籤的定義是這樣的:java.lang.NoSuchMethodError與@PreAuthorize註釋
<http auto-config="false" disable-url-rewriting="true"
entry-point-ref="loginUrlAuthenticationEntryPoint" use-expressions="true">
...
然而,當我想使用基於方法的安全性像:
@RequestMapping(method = RequestMethod.GET)
@PreAuthorize("hasRole('ROLE_USER')")
public
@ResponseBody
List<Lenhos> getAllLenhosInJSON() {
return new ArrayList<Lenhos>(lenhoMap.values());
}
和運行我的應用程序在網絡側獲取未找到404錯誤,錯誤是在Tomcat的如下:
ERROR ContextLoader:220 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'LenhoConf' defined in file [/web-core/target/web-core/WEB-INF/classes/com/almen/donho/webcore/controller/LenhoConf.class]: Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4681)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5184)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5179)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:636)
Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:47)
at net.sf.cglib.core.DefaultGeneratorStrategy.getClassWriter(DefaultGeneratorStrategy.java:30)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:144)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:116)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
at org.springframework.aop.framework.Cglib2AopProxy.createEnhancer(Cglib2AopProxy.java:228)
at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:170)
at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:112)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:476)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:362)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:322)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:407)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1426)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
... 19 more
當我加入@PreAuthorize("hasRole('ROLE_USER')")
時發生錯誤。什麼可能是該錯誤的原因?
PS:1個我pom.xml文件如下:
<properties>
<spring.version>3.0.5.RELEASE</spring.version>
</properties>
<!-- Spring 3 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring security dependencies -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Jackson JSON Mapper -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<build>
<finalName>web-core</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
我不會在我的項目中使用休眠,但是我導入一些模塊(我用的IntelliJ IDEA)到我的應用程序和他們使用。當我運行我的應用程序時,沒有任何與Hibernate相關的運行。我對Spring很陌生。
PS 2: 這是我的依賴關係樹:我用我的應用程序的
[INFO] [dependency:tree {execution: default-cli}]
[INFO] xxx:web-core:war:1.0-SNAPSHOT
[INFO] +- :xxx-yyy:jar:1.0-SNAPSHOT:compile
[INFO] | +- org.springframework:spring-aop:jar:3.0.5.RELEASE:compile
[INFO] | \- org.hibernate:hibernate-entitymanager:jar:3.6.6.Final:compile
[INFO] | \- cglib:cglib:jar:2.2:compile
[INFO] \- xxx:zzz:jar:1.0-SNAPSHOT:compile
[INFO] \- org.hibernate:hibernate:jar:3.2.7.ga:compile
[INFO] +- asm:asm-attrs:jar:1.5.3:compile
[INFO] \- asm:asm:jar:1.5.3:compile
YYY ZZZ和其他模塊。
PS 3: 我的新的依賴關係樹:
[INFO] xxx:web-core:war:1.0-SNAPSHOT
[INFO] \- xxx-yyy:jar:1.0-SNAPSHOT:compile
[INFO] +- org.springframework:spring-aop:jar:3.0.5.RELEASE:compile
[INFO] +- org.hibernate:hibernate-commons-annotations:jar:3.3.0.ga:compile
[INFO] | \- org.hibernate:hibernate:jar:3.2.1.ga:compile
[INFO] | +- asm:asm-attrs:jar:1.5.3:compile
[INFO] | \- asm:asm:jar:1.5.3:compile
[INFO] \- org.hibernate:hibernate-entitymanager:jar:3.6.6.Final:compile
[INFO] \- cglib:cglib:jar:2.2:compile
如果您可以列出以下庫的EXACT版本,將會非常有幫助:Spring Security,Spring AOP,CGLIB,ASM。而且,你是否在同一個應用程序中使用Hibernate?如果是的話,那麼也是Hibernate的版本。 –
@Neeme Praks我編輯了我的問題。 – kamaci
謝謝,POM很有用,但更有用的是查看實際的依賴關係樹。你可以運行「mvn dependency:tree -Dincludes = asm,cglib,org.springframework:spring-aop」並將結果添加到你的問題中嗎? –