avatar
Spring菜鸟求救# Java - 爪哇娇娃
x*m
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)
avatar
s*y
2
应该是你的Spring包没有导对 可能版本不对
avatar
l*o
3
用 4.0.4,检查pom,去掉asm reference
avatar
g*g
4
不同spring jar的版本不一致。
avatar
c*e
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." );
: }

avatar
x*m
6
搞定了,把asm去掉就好了,spring的这些dependency怎么这么乱,相互兼容性好差。
avatar
m*u
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怎么这么乱,相互兼容性好差。
avatar
T*g
8
內什么,你应该用下maven。show effective让你的依赖一目了然

【在 x******m 的大作中提到】
: 搞定了,把asm去掉就好了,spring的这些dependency怎么这么乱,相互兼容性好差。
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。