x******m 发帖数: 736 | 1 跟着网上的tutorial学习,一模一样的code,总是出错。
第一个class
package com.springinaction.springidol;
public class SpellChecker {
public SpellChecker(){
System.out.println("Inside SpellChecker constructor." );
}
public void checkSpelling() {
System.out.println("Inside checkSpelling." );
}
}
第二个class
package com.springinaction.springidol;
public class TextEditor {
private SpellChecker spellChecker;
public TextEditor(SpellChecker spellChecker) {
System.out.println("Inside TextEditor constructor." );
this.spellChecker = spellChecker;
}
public void spellCheck() {
spellChecker.checkSpelling();
}
}
然后main
package com.springinaction.springidol;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MainApp {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("com/
springinaction/springidol/spring-idol.xml");
TextEditor te = (TextEditor) context.getBean("textEditor");
te.spellCheck();
}
}
这是xml
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-3.0.xsd">
run MainApp的时候
为什么总是报错:
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(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:
142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.springframework.core.LocalVariableTableParameterNameDiscoverer.
inspectClass(LocalVariableTableParameterNameDiscoverer.java:112)
at org.springframework.core.LocalVariableTableParameterNameDiscoverer.
getParameterNames(LocalVariableTableParameterNameDiscoverer.java:85)
at org.springframework.beans.factory.support.ConstructorResolver.
autowireConstructor(ConstructorResolver.java:190)
at org.springframework.beans.factory.support.
AbstractAutowireCapableBeanFactory.autowireConstructor(
AbstractAutowireCapableBeanFactory.java:1075)
at org.springframework.beans.factory.support.
AbstractAutowireCapableBeanFactory.createBeanInstance(
AbstractAutowireCapableBeanFactory.java:979)
at org.springframework.beans.factory.support.
AbstractAutowireCapableBeanFactory.doCreateBean(
AbstractAutowireCapableBeanFactory.java:487)
at org.springframework.beans.factory.support.
AbstractAutowireCapableBeanFactory.createBean(
AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.
getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.
DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:
223)
at org.springframework.beans.factory.support.AbstractBeanFactory.
doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.
preInstantiateSingletons(DefaultListableBeanFactory.java:628)
at org.springframework.context.support.AbstractApplicationContext.
finishBeanFactoryInitialization(AbstractApplicationContext.java:872)
at org.springframework.context.support.AbstractApplicationContext.
refresh(AbstractApplicationContext.java:423)
at org.springframework.context.support.ClassPathXmlApplicationContext.<
init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<
init>(ClassPathXmlApplicationContext.java:83)
at com.springinaction.springidol.MainApp.main(MainApp.java:7) |
s****y 发帖数: 503 | |
l*******o 发帖数: 250 | 3 用 4.0.4,检查pom,去掉asm reference |
g*****g 发帖数: 34805 | |
c*********e 发帖数: 16335 | 5 spring最花時間的就是调试,用eclipse, maven, spring调试的时候,可能是pom里的
几个spring-core什么的版本不一致,或者在4.0以後还加了asm. 最好找个调好的,直
接把xml里面的code拷贝过来。
【在 x******m 的大作中提到】 : 跟着网上的tutorial学习,一模一样的code,总是出错。 : 第一个class : package com.springinaction.springidol; : public class SpellChecker { : public SpellChecker(){ : System.out.println("Inside SpellChecker constructor." ); : } : public void checkSpelling() { : System.out.println("Inside checkSpelling." ); : }
|
x******m 发帖数: 736 | 6 搞定了,把asm去掉就好了,spring的这些dependency怎么这么乱,相互兼容性好差。 |
m*****u 发帖数: 1342 | 7 Probably has something to do with the J2EE (JEE), the pom.xml and Maven
helps the dependency problem, but did not eliminate it :-)
【在 x******m 的大作中提到】 : 搞定了,把asm去掉就好了,spring的这些dependency怎么这么乱,相互兼容性好差。
|
T*********g 发帖数: 496 | 8 內什么,你应该用下maven。show effective让你的依赖一目了然
【在 x******m 的大作中提到】 : 搞定了,把asm去掉就好了,spring的这些dependency怎么这么乱,相互兼容性好差。
|