Spring Maven项目集成Springboot
2017-03-26 15:21
387 查看
Maven管理的Spring项目,准备集成Springboot做接口
1、Springboot对Spring有版本要求
我用的Springboot版本:1.4.5.RELEASE,对应Spring的版本为:4.3.7.RELEASE
2、项目的pom文件添加springboot引用:
3、nspringboot模块的pom.xml如下:
4、启动数据库监听 ApplicationStartListener
5、程序启动文件 Application:
6、其他注意点:
1)Maven模块灰色显示:删除,重新导入一次即可
http://blog.csdn.net/Justnow_/article/details/52461197
2)springboot启动不了
原因,发布的不能是自己加进去的,用生成的就好了
3)Springboot启动不了,Spring版本问题:
原来版本:3.1.4 升级到 4.3.7 即可。
7、参考文章:
模块中添加Springboot:
http://blog.csdn.net/buyi_/article/details/51298811
http://www.tuicool.com/articles/RJJvMj3
Springboot配置:
http://blog.csdn.net/yxsimple/article/details/46771123
8、模块下载:下载
1、Springboot对Spring有版本要求
我用的Springboot版本:1.4.5.RELEASE,对应Spring的版本为:4.3.7.RELEASE
2、项目的pom文件添加springboot引用:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${springboot.version}</version> <type>pom</type> <scope>import</scope> </dependency>
3、nspringboot模块的pom.xml如下:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <artifactId>nroot</artifactId> <groupId>com.nankang.cati</groupId> <version>${myapp.version}</version> </parent> <artifactId>nspringboot</artifactId> <packaging>war</packaging> <dependencies> <dependency> <groupId>com.nankang.cati</groupId> <artifactId>nutil</artifactId> <version>${myapp.version}</version> </dependency> <!-- springboot --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <!-- mybatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </dependency> <!-- mysql driver --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <!-- oracle driver --> <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <scope>runtime</scope> </dependency> <!-- junit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <!-- druid db pool --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> </dependency> </dependencies> <build> <finalName>nspringboot</finalName> </build> </project>
4、启动数据库监听 ApplicationStartListener
package com.nankang.cati.nspringboot.listener; import com.nankang.cati.nutil.context.RunTimeController; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; @Component("ApplicationStartListener") public class ApplicationStartListener implements ServletContextListener { public void contextInitialized(ServletContextEvent servletContextEvent) { Logger logger = LoggerFactory.getLogger(this.getClass()); logger.info("Application Starting..."); try { RunTimeController.start(); } catch (Throwable e) { throw new RuntimeException("Application failed to startup.", e); } logger.info("Application Started [OK]."); } public void contextDestroyed(ServletContextEvent servletContextEvent) { Logger logger = LoggerFactory.getLogger(this.getClass()); logger.info("Application Stopping..."); try { RunTimeController.close(); } catch (Throwable e) { throw new RuntimeException("Application failed to stop.", e); } logger.info("Application Stopped [OK]."); } }
5、程序启动文件 Application:
package com.nankang.cati.nspringboot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.support.SpringBootServletInitializer; @SpringBootApplication public class Application extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class); } public static void main(String[] args) throws Exception { SpringApplication.run(Application.class, args); } }
6、其他注意点:
1)Maven模块灰色显示:删除,重新导入一次即可
http://blog.csdn.net/Justnow_/article/details/52461197
2)springboot启动不了
原因,发布的不能是自己加进去的,用生成的就好了
3)Springboot启动不了,Spring版本问题:
原来版本:3.1.4 升级到 4.3.7 即可。
7、参考文章:
模块中添加Springboot:
http://blog.csdn.net/buyi_/article/details/51298811
http://www.tuicool.com/articles/RJJvMj3
Springboot配置:
http://blog.csdn.net/yxsimple/article/details/46771123
8、模块下载:下载
相关文章推荐
- SpringBoot+Maven项目实战(2):集成SpringBoot
- Maven管理的Spring Web项目集成JUnit单元测试
- maven 项目(三)引申--spring集成hibernate+JPA事务配置(扫描注解)
- springmvc+spring+mybatis+maven项目集成shiro进行用户权限控制【转】
- maven项目管理 集成常见错误一解决:spring 在启动服务器的时候报错 Could not open ServletContext resource [/WEB-INF/dispather-se
- Spring+SpringMVC+Mybatis+Restful+Maven多模块项目集成
- Maven管理的Spring Web项目集成JUnit单元测试
- springmvc+spring+mybatis+maven项目集成shiro进行用户权限控制【转】
- SpringBoot+Maven项目实战(4):集成Mybatis
- SpringBoot+Maven项目实战(2):集成SpringBoot
- Spring集成React用来开发前端----maven项目中用webpack打包react相关组件
- 通过注解的方式集成Spring 4 MVC+Hibernate 4+MySQL+Maven,开发项目样例
- springmvc+spring+mybatis+maven项目集成shiro进行用户权限控制【转】
- maven 项目(四) spring集成springMVC开发统一接入API(准备工作:第二部分)
- springmvc+spring+mybatis+maven项目集成shiro进行用户权限控制【转】
- maven 项目(三) spring集成mybatis事务配置(扫描注解)
- eclipse 下搭建 maven项目。spring+springMvc+mybatise框架集成
- maven 项目(四) spring集成springMVC开发统一接入API(准备工作:第一部分)
- 【SSMS】springmvc+spring+mybatis+maven项目集成shiro进行用户权限控制
- SpringBoot+Maven项目实战(5):集成分页插件