使用的是 spring cloud alibaba 2021.0.1 + spring boot 2.6.4 目录布局: 1、common模块:存放 model、mapper、service、impl、连接数据库、统一异常处理、redis josn数据格式化、统一响应、swagger、mp、cors 2、merchant模块(商户端):主要编辑controller对外开放api接口 3、supply模块(供货商):主要编辑controller对外开放api接口 问题描述: 目前在做 merchant模块,启动时提示错误: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springApplicationAdminRegistrar' defined in class path resource [org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Admin,name=SpringApplication "de153284ee0293c1957a1adb5b4189c.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241005/8243f67869e656150c1229aeba1c8e5a.png) 尝试3~5小时没解决,特来思否求助大佬们 特别描述: 1、目前swagger2实际测试成功。将swagger2全部内容放到common模块,在商户端编写controller时,进行添加注解接口:启动 swagger2可以显示商户端的端口中打开文档地址显示controller中定义的接口文档 尝试失败过的方法: 1、在启动类上加包扫描:结果失败,提示另一个错误 // @SpringBootApplication @SpringBootApplication(scanBasePackages = "com.quanneng") @Slf4j @MapperScan("com.quanneng.mapper") public class MerchantApiApplication { …… } Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springApplicationAdminRegistrar' defined in class path resource [org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Admin,name=SpringApplication -->后百度,解决无果 2、尝试 @ComponentScan({"com.*"}) public class MerchantApiApplication { …… } Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'merchantController': Unsatisfied dependency expressed through field 'merchantService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'merchantService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'merchantMapper' defined in file [D:\biancheng\git_cangku_java_spring_cloud_alibaba\liuliang_mall_java\common\target\classes\com\quanneng\mapper\MerchantMapper.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required -->配置了 mybatisPlusConfig 无果、添加 datasource 到 merchant 模块yml文件 无果。
项目引入sentinel之后,启动报错multiple SLF4J bindings,写了exclusion,把slf4j排除后,依然报错, com.alibaba.cloud spring-cloud-starter-alibaba-sentinel 2.2.9.RELEASE org.slf4j slf4j-log4j12 "C:\Program Files\Java\jdk1.8.0_301\bin\java.exe" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:58922,suspend=y,server=n -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -javaagent:C:\Users\issuser\AppData\Local\JetBrains\IntelliJIdea2022.3\captureAgent\debugger-agent.jar -Dfile.encoding=UTF-8 -classpath C:\Users\issuser\AppData\Local\Temp\classpath839542257.jar com.haier.cosmo.im.base.Application Connected to the target VM, address: '127.0.0.1:58922', transport: 'socket' SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/Users/issuser/Desktop/suiwei/app/apache-maven-3.9.0/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/issuser/Desktop/suiwei/app/apache-maven-3.9.0/repository/org/slf4j/slf4j-log4j12/1.7.24/slf4j-log4j12-1.7.24.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder] 2024-05-11 21:07:29.148 [main] ERROR org.springframework.boot.SpringApplication - Application startup failed java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/source/ConfigurationPropertySources at org.springframework.cloud.client.HostInfoEnvironmentPostProcessor.getFirstNonLoopbackHostInfo(HostInfoEnvironmentPostProcessor.java:62) at org.springframework.cloud.client.HostInfoEnvironmentPostProcessor.postProcessEnvironment(HostInfoEnvironmentPostProcessor.java:51) at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:171) at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:157) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122) at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:73) at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:336) at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) at com.haier.cosmo.im.base.Application.main(Application.java:22) Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.properties.source.ConfigurationPropertySources at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:418) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ... 14 common frames omitted Disconnected from the target VM, address: '127.0.0.1:58922', transport: 'socket' Process finished with exit code 1