maven项目转成spring boot项目有两种方式
2017-12-27 02:04
796 查看
maven项目转成spring boot项目有两种方式:
1、继承方式,pom.xml文件中配置
2、导入pom文件的方式,在pom.xml文件中导入spring-boot-dependencies工程pom文件
针对第二种方式,主要是解决需要继承自定义父工程的场景,因为在spring-boot-dependencies的pom中已经定义了很多依赖管理dependencyManager,因此在自有父工程的pom中不要出现依赖管理和spring-boot-dependencies存在冲突的情况,比如导入的spring-boot-dependencies版本是1.5.9.release,那么默认就导入了如下的依赖管理
如果在项目的其他pom文件中也增加了依赖管理,出现了版本不一致的情况如下
那么如果该依赖dependency到项目中,启动时会出现类库冲突异常,如下
因此在管理spring boot项目时,一定要保证依赖的类库版本是一致的
1、继承方式,pom.xml文件中配置
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> </parent>
2、导入pom文件的方式,在pom.xml文件中导入spring-boot-dependencies工程pom文件
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>1.5.9.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
针对第二种方式,主要是解决需要继承自定义父工程的场景,因为在spring-boot-dependencies的pom中已经定义了很多依赖管理dependencyManager,因此在自有父工程的pom中不要出现依赖管理和spring-boot-dependencies存在冲突的情况,比如导入的spring-boot-dependencies版本是1.5.9.release,那么默认就导入了如下的依赖管理
<dependencyManagement> <dependencies> <!-- Spring Boot --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot</artifactId> <version>1.5.9.release</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-test</artifactId> <version>1.5.9.release</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-test-autoconfigure</artifactId> <version>1.5.9.release</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-actuator</artifactId> <version>1.5.9.release</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-actuator-autoconfigure</artifactId> <version>1.5.9.release</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-autoconfigure</artifactId> <version>1.5.9.release</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-autoconfigure-processor</artifactId> <version>1.5.9.release</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-metadata</artifactId> <version>1.5.9.release</version> </dependency> ........
如果在项目的其他pom文件中也增加了依赖管理,出现了版本不一致的情况如下
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-actuator-autoconfigure</artifactId> <version>1.3.5.release</version> </dependency>
那么如果该依赖dependency到项目中,启动时会出现类库冲突异常,如下
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.5.9.RELEASE) 2017-12-27 01:44:25.572 INFO 23408 --- [ main] com.ibm.edp.dictionary.Startup : Starting Startup on xujian-PC with PID 23408 (D:\projects\ibm\edp\edp-dictionary\edp-dictionary-web\target\classes started by xujian in D:\projects\ibm\edp\edp-dictionary\edp-dictionary-web) 2017-12-27 01:44:25.576 INFO 23408 --- [ main] com.ibm.edp.dictionary.Startup : The following profiles are active: dev 2017-12-27 01:44:25.704 INFO 23408 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4fe767f3: startup date [Wed Dec 27 01:44:25 CST 2017]; root of context hierarchy 2017-12-27 01:44:26.204 WARN 23408 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.ibm.edp.dictionary.Startup]; nested exception is java.lang.IllegalArgumentException: Cannot instantiate factory class: org.springframework.boot.autoconfigure.AutoConfigurationImportFilter 2017-12-27 01:44:26.450 ERROR 23408 --- [ main] o.s.boot.SpringApplication : Application startup failed org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.ibm.edp.dictionary.Startup]; nested exception is java.lang.IllegalArgumentException: Cannot instantiate factory class: org.springframework.boot.autoconfigure.AutoConfigurationImportFilter at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:462) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:186) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE] at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:321) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE] at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:98) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:678) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:520) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE] at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE] at com.ibm.edp.dictionary.Startup.main(Startup.java:26) [classes/:na] Caused by: java.lang.IllegalArgumentException: Cannot instantiate factory class: org.springframework.boot.autoconfigure.AutoConfigurationImportFilter at org.springframework.core.io.support.SpringFactoriesLoader.instantiateFactory(SpringFactoriesLoader.java:138) ~[spring-core-4.2.6.RELEASE.jar:4.2.6.RELEASE] at org.springframework.core.io.support.SpringFactoriesLoader.loadFactories(SpringFactoriesLoader.java:91) ~[spring-core-4.2.6.RELEASE.jar:4.2.6.RELEASE] at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getAutoConfigurationImportFilters(AutoConfigurationImportSelector.java:280) ~[spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE] at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.filter(AutoConfigurationImportSelector.java:251) ~[spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE] at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.selectImports(AutoConfigurationImportSelector.java:102) ~[spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:454) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE] ... 13 common frames omitted Caused by: java.lang.IllegalAccessException: Class org.springframework.core.io.support.SpringFactoriesLoader can not access a member of class org.springframework.boot.autoconfigure.condition.OnClassCondition with modifiers "" at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102) ~[na:1.8.0_101] at java.lang.Class.newInstance(Class.java:436) ~[na:1.8.0_101] at org.springframework.core.io.support.SpringFactoriesLoader.instantiateFactory(SpringFactoriesLoader.java:135) ~[spring-core-4.2.6.RELEASE.jar:4.2.6.RELEASE] ... 18 common frames omitted
因此在管理spring boot项目时,一定要保证依赖的类库版本是一致的
相关文章推荐
- 基于Maven的SpringBoot项目实现热部署的两种方式
- 基于Maven的SpringBoot项目实现热部署的两种方式
- 基于Maven的SpringBoot项目实现热部署的两种方式
- 基于Maven的SpringBoot项目实现热部署的两种方式
- 通过IntelliJ IDEA创建spring boot 项目的两种方式之方式二
- java web项目 maven springboot 框架 以jar方式如何部署到服务器上
- 通过IntelliJ IDEA创建spring boot 项目的两种方式之方式一
- <springBoot>(三)(入门篇)新建一个springBoot项目(两种启动的方式)
- Maven构建一个多模块的Spring Boot + Spring MVC项目,完全基于java config
- springboot搭建项目之日志AOP,支持日志内容可配置控制(黑名单字段不会打印或其他处理方式)
- maven搭建springboot多模块项目
- springboot 集成 elasticsearch(maven项目)
- myeclipse创建spring boot maven项目
- 使用Maven插件构建SpringBoot项目,生成Docker镜像push到DockerHub上
- 使用maven 快速搭建springboot项目
- Springboot 多模块 整合 Mybatis maven项目
- spring boot 项目打包jar 启动方式,以及 可能遇到的坑。
- Spring-boot中读取config配置文件的两种方式
- SpringBoot之——热部署的两种方式
- maven构建的spring boot项目打包成可执行的jar(fat jar)