分享我的一个问题解决:

在module-info-java中添加相关exports即可

module test {requires spring.context;requires junit;exports test;exports POJO;exports service;
}

报错提示: /Users/wgx/Library/Java/JavaVirtualMachines/openjdk-18.0.2.1/Contents/Home/bin/java -ea -Didea.test.cyclic.buffer.size=1048576 -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=59750:/Applications/IntelliJ IDEA.app/Contents/bin --add-reads test=ALL-UNNAMED --add-opens test/test=ALL-UNNAMED --add-modules test -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath /Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar:/Applications/IntelliJ IDEA.app/Contents/plugins/junit/lib/junit5-rt.jar:/Applications/IntelliJ IDEA.app/Contents/plugins/junit/lib/junit-rt.jar:/Users/wgx/Downloads/mysql-connector-java-8.0.30/mysql-connector-java-8.0.30.jar:/Users/wgx/.m2/repository/org/springframework/spring-aop/5.3.18/spring-aop-5.3.18.jar:/Users/wgx/.m2/repository/org/springframework/spring-beans/5.3.18/spring-beans-5.3.18.jar:/Users/wgx/.m2/repository/org/springframework/spring-core/5.3.18/spring-core-5.3.18.jar:/Users/wgx/.m2/repository/org/springframework/spring-jcl/5.3.18/spring-jcl-5.3.18.jar:/Users/wgx/.m2/repository/org/springframework/spring-expression/5.3.18/spring-expression-5.3.18.jar:/Users/wgx/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar -p /Users/wgx/IdeaProjects/GarsonSpring/target/classes:/Users/wgx/.m2/repository/junit/junit/4.13.2/junit-4.13.2.jar:/Users/wgx/.m2/repository/org/springframework/spring-context/5.3.18/spring-context-5.3.18.jar com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 test.SpringTest,testRuns
调用StudentService无参构造
10月 02, 2022 4:06:45 下午 org.springframework.context.support.AbstractApplicationContext refresh
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'StudentService' defined in class path resource [bean2.xml]: Cannot resolve reference to bean 'StudentDao' while setting bean property 'studentDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'StudentDao' defined in class path resource [bean2.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [dao.StudentDaoImpl]: Is the constructor accessible?; nested exception is java.lang.IllegalAccessException: class org.springframework.beans.BeanUtils cannot access class dao.StudentDaoImpl (in module test) because module test does not export dao to unnamed module @34b7ac2f

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'StudentService' defined in class path resource [bean2.xml]: Cannot resolve reference to bean 'StudentDao' while setting bean property 'studentDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'StudentDao' defined in class path resource [bean2.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [dao.StudentDaoImpl]: Is the constructor accessible?; nested exception is java.lang.IllegalAccessException: class org.springframework.beans.BeanUtils cannot access class dao.StudentDaoImpl (in module test) because module test does not export dao to unnamed module @34b7ac2f

at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:342)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:113)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1707)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1452)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953)
    at spring.context@5.3.18/org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
    at spring.context@5.3.18/org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
    at spring.context@5.3.18/org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
    at spring.context@5.3.18/org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
    at test/test.SpringTest.testRuns(SpringTest.java:26)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:577)
    at junit@4.13.2/org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at junit@4.13.2/org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at junit@4.13.2/org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at junit@4.13.2/org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at junit@4.13.2/org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at junit@4.13.2/org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at junit@4.13.2/org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at junit@4.13.2/org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at junit@4.13.2/org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
    at junit@4.13.2/org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at junit@4.13.2/org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at junit@4.13.2/org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at junit@4.13.2/org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at junit@4.13.2/org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at junit@4.13.2/org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at junit@4.13.2/org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at junit@4.13.2/org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
    at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'StudentDao' defined in class path resource [bean2.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [dao.StudentDaoImpl]: Is the constructor accessible?; nested exception is java.lang.IllegalAccessException: class org.springframework.beans.BeanUtils cannot access class dao.StudentDaoImpl (in module test) because module test does not export dao to unnamed module @34b7ac2f
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1334)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1232)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:330)
    ... 40 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [dao.StudentDaoImpl]: Is the constructor accessible?; nested exception is java.lang.IllegalAccessException: class org.springframework.beans.BeanUtils cannot access class dao.StudentDaoImpl (in module test) because module test does not export dao to unnamed module @34b7ac2f
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:218)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1326)
    ... 48 more
Caused by: java.lang.IllegalAccessException: class org.springframework.beans.BeanUtils cannot access class dao.StudentDaoImpl (in module test) because module test does not export dao to unnamed module @34b7ac2f
    at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:394)
    at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:674)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:492)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:483)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:211)
    ... 50 more

进程已结束,退出代码255

JavaSpring中Exception encountered during context initialization - cancelling refresh attempt:相关推荐

  1. Exception encountered during context initialization - cancelling refresh attempt

    场景 在main/java包下创建了两个类Student和Address ,其中Student类中定义了一个Address类的变量,private Address address:此时在resourc ...

  2. 警告: Exception encountered during context initialization - cancelling refresh attempt: org.springfram

    警告: Exception encountered during context initialization - cancelling refresh attempt: org.springfram ...

  3. Spring AOP 报错 Exception encountered during context initialization - cancelling refresh attempt[已解决]

    三月 19, 2018 4:01:40 下午 org.springframework.context.support.AbstractApplicationContext prepareRefresh ...

  4. Exception encountered during context initialization - cancelling refresh attempt:org.springframework

    我这里是在springboot子模块里发生的错误,如下 Exception encountered during context initialization - cancelling refresh ...

  5. 使用swagger报错:Exception encountered during context initialization - cancelling refresh attempt解决方法

    今天在使用swagger时遇到了如下报错: WARN 19704 --- [ main] ConfigServletWebServerApplicationContext :Exception enc ...

  6. 警告: Exception encountered during context initialization - cancelling refresh attempt:

    今天写Spring遇到了一个坑爹的问题,那么因为啥原因呢? 错误提示我错误的加载了Bean 警告: Exception encountered during context initializatio ...

  7. 警告: Exception encountered during context initialization - cancelling refresh attempt

    警告: Exception encountered during context initialization - cancelling refresh attempt: org.springfram ...

  8. Spring报错:Exception encountered during context initialization - cancelling refresh attempt: org.sprin

    在使用aop时报错: 十一月 06, 2021 4:15:21 下午 org.springframework.context.support.AbstractApplicationContext re ...

  9. 关于异常:警告: Exception encountered during context initialization - cancelling refresh attempt

    警告: Exception encountered during context initialization - cancelling refresh attempt: org.springfram ...

最新文章

  1. 别乱提交代码了,看下大厂 Git 提交规范是怎么做的!
  2. Debian 下如何安装 Java
  3. Google Map API 学习六-设置infoWindow的长宽
  4. caffe 关于Deconvolution的初始化注意事项
  5. c语言 汇编中断程序,ARM7 C语言嵌入汇编开关中断
  6. 正则表达式的先行断言(lookahead)和后行断言(lookbehind)
  7. 《Spring》(十一) ---- 基于注解的依赖注入
  8. 如何写出优秀的开源简历
  9. java摇两个色子代码_[代码全屏查看]-html5+原生js实现的一个简易双色子游戏
  10. java for循环
  11. MapReduce之InputFormat、OutputFormat(三)
  12. 休闲娱乐 - 夏日自制饮料
  13. Vivado综合设置之-gated_clock_conversion
  14. createjs php通信,快速入门createjs实例教程
  15. java设计模式——装饰模式
  16. web课程设计网页规划与设计:个人毕设网站设计 —— 二手书籍(11个页面) HTML+CSS+JavaScript...
  17. 美团外卖uml流程图_美团即时物流的分布式系统架构设计
  18. ios和Android常见的兼容问题
  19. 基于JAVA模拟考试系统计算机毕业设计源码+数据库+lw文档+系统+部署
  20. 计算机语言三分钟怎么写,普通话三分钟范文

热门文章

  1. 论无名合同及其法律适用
  2. linux下virtualbox使用
  3. 中国互联网+物流行业应用模式与市场需求预测报告2022版
  4. 《刘慈欣的思想实验室》笔记
  5. 互联网晚报 | 董明珠称格力员工一人一套房承诺不变;工信部:自动续费前5日应以显著方式提醒;诺基亚近60年来首次更换新Logo...
  6. 计算机图形学之组合图形的绘制(主要是渐变的实现)
  7. PHP后端美化,PHPCMS V9后台模板美化 PHPCMS后台美化模版 - 下载 - 搜珍网
  8. CryptoHack-wp(一)
  9. 详解C++中的构造函数
  10. 二进制转十进制和八进制