我把名字打长就会有人跟着念 2022-03-07 19:48 采纳率: 70%
浏览 72
已结题

同志们年轻人第一个Spring框架程序就遇到了这样的问题该怎么办啊?


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:
307, 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
307, 2022 7:34:33 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [applicationContext.xml]
307, 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文件的问题,但是我一直找不到原因啊

  • 写回答

2条回答 默认 最新

  • _雪菜肉丝面_ 2022-03-07 19:59
    关注

    applicationContext.xml前面带个 classpath: 试试看

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月15日
  • 已采纳回答 3月7日
  • 创建了问题 3月7日

悬赏问题

  • ¥15 快手联盟怎么快速的跑出建立模型
  • ¥20 ros环境下运行orb-slam一直报错
  • ¥15 关于腾讯云服务器中,PHP页面无法打开的问题
  • ¥60 如何把照片修复成原始拍摄图
  • ¥80 Exited too quickly (process log may have details)
  • ¥15 爬知乎登录之后内容加载不出来
  • ¥15 怎么用protues测量通频带
  • ¥15 zepelin使用sparkInterpreter 异常
  • ¥15 paho mqtt 接收不到消息
  • ¥15 函数r关于两个分量y,z方向上的图像,分开画r随y的图像,r随z的图像