您好我使用EclipseEE和Java8_40。我从Spring Framework开始并遇到一些问题。当我想在beans.xml中使用构造函数时,程序会创建一个Exception。
我有CLASSPATH:
- commons-logging-1.2.jar
- commons-logging-1.2-javadoc.jar
和春天* .jars
- spring-aop-4.1.5.RELEASE.jar
- spring-asm-3.1.1.RELEASE.jar
- spring-beans-4.1.5.RELEASE.jar
- spring-context-4.1.5.RELEASE.jar
- spring-aspects-4.1.5.RELEASE.jar
- spring-context-support-4.1.5.RELEASE.jar
- spring-core-4.1.5.RELEASE.jar
- spring-web-4.1.5.RELEASE.jar
- spring-webmvc-4.1.5.RELEASE.jar
- spring-expression-4.1.5.RELEASE.jar
SPRING BEAN
package beans;
public class SequenceGenerator {
private String prefix;
private String suffix;
private int initial;
private int counter;
public SequenceGenerator() {}
public SequenceGenerator(String prefix, String suffix, int initial) {
this.prefix = prefix;
this.suffix = suffix;
this.initial = initial; }
public void setPrefix(String prefix) {
this.prefix = prefix; }
public void setSuffix(String suffix) {
this.suffix = suffix; }
public void setInitial(int initial) {
this.initial = initial; }
public synchronized String getSequence() {
StringBuffer buffer = new StringBuffer();
buffer.append(prefix);
buffer.append(initial + counter++);
buffer.append(suffix);
return buffer.toString(); }
}
CLIENT
package klient.program;
import org.springframework.context.*;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import beans.SequenceGenerator;
public class Program {
@SuppressWarnings("resource")
public static void main(String [] args){
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
SequenceGenerator generator = (SequenceGenerator) context.getBean("sequenceGenerator");
System.out.println(generator.getSequence());
System.out.println(generator.getSequence());
}
}
的beans.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">
<bean name="sequenceGenerator" class="beans.SequenceGenerator">
<constructor-arg><value>30</value></constructor-arg>
<constructor-arg><value>A</value></constructor-arg>
<constructor-arg><value>100000</value></constructor-arg>
</bean>
</beans>
例外:
Exception in thread "main" java.lang.IncompatibleClassChangeError: class org.springframework.core.LocalVariableTableParameterNameDiscoverer$ParameterNameDiscoveringVisitor has interface org.springframework.asm.ClassVisitor as super class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.springframework.core.LocalVariableTableParameterNameDiscoverer.inspectClass(LocalVariableTableParameterNameDiscoverer.java:114)
at org.springframework.core.LocalVariableTableParameterNameDiscoverer.getParameterNames(LocalVariableTableParameterNameDiscoverer.java:87)
at org.springframework.core.PrioritizedParameterNameDiscoverer.getParameterNames(PrioritizedParameterNameDiscoverer.java:65)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:182)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1131)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1034)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at klient.program.Program.main(Program.java:8)
答案 0 :(得分:2)
你不需要spring-asm-(版本).jar。 这种依赖关系早在春天核心:
但请注意,我们已经取消了M2中专用的spring-asm jar 支持直接包含org.springframework.asm类 弹簧核心。对于JDK7用户来说,这两个升级都是好消息 以动态JVM语言编写Spring组件,就像这些新的一样 CGLIB和ASM的版本正确处理新的invokedynamic JDK7中引入的字节码指令。
http://spring.io/blog/2012/09/12/spring-framework-3-2-m2-released
如何写在这里:https://github.com/spring-projects/spring-framework/commit/c16f18a5fd659f34d6290b5f2cffe54534b7592a此模块已完全删除,而是使用ASM 4