首页 新闻 赞助 找找看

springboot项目 将依赖单独打包后找不到类

0
悬赏园豆:60 [已解决问题] 解决于 2022-01-26 18:19

说明
springboot项目 将依赖单独打包放入lib后 springboot启动时 找不到类
启动时找到了启动类 后面main方法执行时 报找不见这个类 SpringApplication.run(GatewayApp.class);

之前出现过类似的问题,就是lib里面的jar 访问不到 我主项目里面的类,我把需要访问的类单独打jar包放入lib 就可以,在主项目中就不可以
如果不将依赖分离打包是可以正常运行的

项目结构
gateway-api-boot-1.0.0.jar是项目主体
lib里面是一系列的依赖

这是lib里面打开后一系列的依赖

启动报错
'''
2022-01-26 14:31:11.577 [main] ERROR o.s.boot.SpringApplication - Application run failed
java.lang.IllegalArgumentException: Could not find class [com.shilei.gateway.boot.GatewayApp]
at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:334)
at com.alibaba.spring.util.AnnotatedBeanDefinitionRegistryUtils.isPresentBean(AnnotatedBeanDefinitionRegistryUtils.java:67)
at com.alibaba.spring.util.AnnotatedBeanDefinitionRegistryUtils.registerBeans(AnnotatedBeanDefinitionRegistryUtils.java:101)
at org.apache.dubbo.config.spring.context.annotation.DubboConfigConfigurationRegistrar.registerBeanDefinitions(DubboConfigConfigurationRegistrar.java:55)
at org.springframework.context.annotation.ImportBeanDefinitionRegistrar.registerBeanDefinitions(ImportBeanDefinitionRegistrar.java:86)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.lambda$loadBeanDefinitionsFromRegistrars$1(ConfigurationClassBeanDefinitionReader.java:384)
at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:383)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:148)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:120)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:280)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:96)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:707)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:533)
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:62)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at com.shilei.gateway.boot.GatewayApp.main(GatewayApp.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:107)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
'''

很明显启动类和启动入口是找到了的,但是执行启动类时候spring又找不到这个类了,应该是lib中的包访问不到我主体包中的类

这行说明是加载到这个类了
at com.shilei.gateway.boot.GatewayApp.main(GatewayApp.java:25)

but spring就不认这个类,我将这个类单独在lib中单独打个包可以读取到,但是这应该不是正确做法

问题补充:

补充一下
就是站在MANIFEST.MF文件的角度
就是Class-Path下面的包访问不到Spring-Boot-Classes中的类

蓝羽code的主页 蓝羽code | 菜鸟二级 | 园豆:313
提问于:2022-01-26 14:49
< >
分享
最佳答案
0

问题已解决 最后放弃了使用spring-boot-maven-plugin插件
删除了这部分代码
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.shilei.gateway.boot.GatewayApp</mainClass>
<includes>
<include>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
</include>
</includes>
<outputDirectory>${project.build.directory}\build</outputDirectory>
</configuration>
</plugin>

使用maven-jar-plugin 指定启动类
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>com.shilei.gateway.boot.GatewayApp</mainClass>
</manifest>
</archive>
<outputDirectory>${project.build.directory}\build</outputDirectory>
</configuration>
</plugin>

问题就解决了

蓝羽code | 菜鸟二级 |园豆:313 | 2022-01-26 18:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册