在尝试加载Spring 4.3.8应用程序的应用程序上下文时,一直在EmptyVisitor类上获取ClassNotFoundException。我看到spring-asm在3.2中被内联到spring-core中,但如果我查看spring-core jar,那么有几个XXXVisitor类,但没有EmptyVisitor类。
示例代码非常简单。 : - )
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS
使用此应用程序上下文:
public static void main(String[] args)
{
ApplicationContext context = new ClassPathXmlApplicationContext("conf/basic/applicationContext.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"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="removed" />
<property name="url" value="<removed>" />
<property name="username" value="<removed>" />
<property name="password" value="<removed>" />
</bean>
</beans>
这是maven配置:
Apr 29, 2017 12:37:47 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@246b179d: startup date [Sat Apr 29 12:37:47 PDT 2017]; root of context hierarchy
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/asm/commons/EmptyVisitor
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.springframework.context.support.AbstractRefreshableApplicationContext.customizeBeanFactory(AbstractRefreshableApplicationContext.java:218)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at greg.aws.rds.redshift.BdlisTest.main(BdlisTest.java:21)
Caused by: java.lang.ClassNotFoundException: org.springframework.asm.commons.EmptyVisitor
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 19 more
答案 0 :(得分:0)
好吧,使用您的配置在Eclipse中执行项目提供了丰富的信息。鉴于你错过了一个至关重要的依赖,我不太确定你是如何达到为你编译的点的:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
您的主要方法不应该编译 - org.springframework.context.ApplicationContext
和org.springframework.context.support.ClassPathXmlApplicationContext
都会带来spring-context
。我的猜测是你已经将旧版本的Spring混合到你的运行时类路径中。
Eclipse Build Path Nesting Errors,我过去常常使用你的pom.xml来解决一个问题,你的项目可能已被&#34; mavenized&#34; - 作为常规Java项目开始,然后给出一个Maven方面。所以你也应该摆脱<sourceDirectory>src</sourceDirectory>
。
在我解决了上述问题之后,我达到了MySQL数据源无法实例化的失败点,这表明我的asm错误比你的更远。
这是我的mvn dependency:tree
:
[INFO] test:testart:jar:0.0.1-SNAPSHOT
[INFO] +- mysql:mysql-connector-java:jar:6.0.6:compile
[INFO] +- org.springframework:spring-context:jar:4.3.8.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:4.3.8.RELEASE:compile
[INFO] | +- org.springframework:spring-beans:jar:4.3.8.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:4.3.8.RELEASE:compile
[INFO] +- org.springframework:spring-core:jar:4.3.8.RELEASE:compile
[INFO] | \- commons-logging:commons-logging:jar:1.2:compile
[INFO] +- org.springframework:spring-jdbc:jar:4.3.8.RELEASE:compile
[INFO] | \- org.springframework:spring-tx:jar:4.3.8.RELEASE:compile
[INFO] \- org.projectlombok:lombok:jar:1.16.16:compile