F:\JDK11\bin\java.exe -javaagent:C:\Users\hmyxh\AppData\Local\JetBrains\IdeaIC2021.3\testAgent\intellij-coverage-agent-1.0.613.jar=C:\Users\hmyxh\AppData\Local\Temp\coverage5args -Didea.new.sampling.coverage=true -Dcoverage.ignore.private.constructor.util.class=true "-javaagent:E:\IntelliJ IDEA Community Edition 2021.3\lib\idea_rt.jar=7596:E:\IntelliJ IDEA Community Edition 2021.3\bin" -Dfile.encoding=UTF-8 -classpath E:\ideaprojects\gradle_test\build\classes\java\main;E:\ideaprojects\gradle_test\build\resources\main;E:\Maven_repository\repository\org\springframework\spring-context\5.0.2.RELEASE\spring-context-5.0.2.RELEASE.jar;E:\Maven_repository\repository\org\springframework\spring-beans\5.0.2.RELEASE\spring-beans-5.0.2.RELEASE.jar;E:\Maven_repository\repository\org\springframework\spring-expression\5.0.2.RELEASE\spring-expression-5.0.2.RELEASE.jar;E:\Maven_repository\repository\org\springframework\spring-core\5.0.2.RELEASE\spring-core-5.0.2.RELEASE.jar;E:\Maven_repository\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;E:\Maven_repository\repository\org\springframework\spring-aop\5.0.2.RELEASE\spring-aop-5.0.2.RELEASE.jar;E:\Maven_repository\repository\org\springframework\spring-jcl\5.0.2.RELEASE\spring-jcl-5.0.2.RELEASE.jar test.Test_SSM
---- IntelliJ IDEA coverage runner ----
sampling ...
include patterns:
test\..*
exclude patterns:
3月 07, 2022 7:34:33 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@6b9651f3: startup date [Mon Mar 07 19:34:33 CST 2022]; root of context hierarchy
3月 07, 2022 7:34:33 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [applicationContext.xml]
3月 07, 2022 7:34:33 下午 org.springframework.context.support.ClassPathXmlApplicationContext refresh
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [...] for bean with name '...' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: ...
Exception in thread "main" org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [...] for bean with name '...' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: ...
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1380)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:670)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:637)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1489)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1007)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:741)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
at test.Test_SSM.main(Test_SSM.java:14)
Caused by: java.lang.ClassNotFoundException: ...
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:255)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:437)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1428)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1372)
... 10 more
Class transformation time: 0.0079924s for 1173 classes or 6.813640238704177E-6s per class
进程已结束,退出代码1
上面就是报错代码,下面是test类的源码
package test;
import dao.TestDaoImpl;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.FileSystemResource;
public class Test_SSM {
public static void main(String[] args)
{
// 用下面这行代码就不会报错
//BeanFactory appCon=new XmlBeanFactory(new FileSystemResource("E:\\ideaprojects\\gradle_test\\src\\main\\resources\\applicationContext.xml"));
ApplicationContext appCon=new ClassPathXmlApplicationContext("applicationContext.xml");
TestDaoImpl tt= (TestDaoImpl) appCon.getBean("test");
tt.sayHello();
}
}
用淘汰了的
BeanFactory appCon=new XmlBeanFactory(new FileSystemResource("E:\\ideaprojects\\gradle_test\\src\\main\\resources\\applicationContext.xml"));
就不会报错但是用
ApplicationContext appCon=new ClassPathXmlApplicationContext("applicationContext.xml");
就会报上面的那种错所以应该不是xml文件的问题,但是我一直找不到原因啊