Spring Maven项目集成Springboot
Maven管理的Spring项目,准备集成Springboot做接口
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:
Spring Maven项目集成Springboot的更多相关文章
- [转帖]spring boot项目集成jacoco
小试牛刀:spring boot项目集成jacoco 2019-03-28 20:14:36 zyq23333 阅读数 509 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议, ...
- Spring Boot 项目集成 Alibaba Druid
Druid 是一个非常好用的数据库连接池,但是他的好并不止体现在作为一个连接池加快数据访问性能上和连接管理上,他带有一个强大的监控工具:Druid Monitor.不仅可以监控数据源和慢查询,还可以监 ...
- springmvc+spring+mybatis+maven项目集成shiro进行用户权限控制【转】
项目结构: 1.maven项目的pom中引入shiro所需的jar包依赖关系 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...
- Spring boot项目集成Neo4j
第一步,创建Springboot工程 使用Eclipse 创建Maven项目,并修改pom.xml文件为: <?xml version="1.0" encoding=&quo ...
- 通过idea 打包 spring maven项目打包为可执行jar包
用assembly打包一直报错: shangyanshuodeMacBook-Pro:target shangyanshuo$ java -jar jobscrawler-1.0-SNAPSHOT-j ...
- Maven项目集成Jetty
1.新建webapp maven项目. 项目目录结构如下. 2.pom文件添加jetty构建. <project xmlns="http://maven.apache.org/POM/ ...
- 测者的测试技术手册:自动化的自动化EvoSuite:Maven项目集成EvoSuite实战
EvoSuite是由Sheffield等大学联合开发的一种开源工具,用于自动生成测试用例集,生成的测试用例均符合Junit的标准,可直接在Junit中运行.得到了Google和Yourkit的支持. ...
- 【Spring Boot&&Spring Cloud系列】Spring Boot项目集成Swagger UI
前言 Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目标是使客户端和文件系统作为服务器以同样的速度来更新.文件的方法,参数和模型紧密集 ...
- spring maven项目解决依赖jar包版本冲突方案
引入:http://blog.csdn.net/sanzhongguren/article/details/71191290 在spring reference中提到一个解决spring jar包之间 ...
随机推荐
- 并查集(Union-Find)
常见问题: 首先在地图上给你若干个城镇,这些城镇都可以看作点,然后告诉你哪些对城镇之间是有道路直接相连的.最后要解决的是整幅图的连通性问题.比如随意给你两个点,让你判断它们是否连通,或者问你整幅图一共 ...
- docker-compose使用volume部署mysql时permission deny问题解决
问题整体情况为使用docker做mysql的容器,然后结合其他服务一起通过docker-compose启动,并且为了一次性建表和设置用户权限我又在mysql中封装了setup.sh.schema.sq ...
- <亲测>阿里云centos7安装redis
安装redis yum install redis 启动redis systemctl start redis.service 设置redis开机启动 systemctl enable redis.s ...
- ALGO-13_蓝桥杯_算法训练_拦截导弹(贪心,DP)
问题描述 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度.某天,雷达捕捉到敌国的导弹 ...
- vc++获取网页源码之使用import+智能指针包装类
创建基于对话框的mfc应用程序 使用智能指针包装类IWinHttpRequestptr,它内部采用的是引用计数来管理对象的生命周期 代码: #import "C:\\Windows\\Sys ...
- 计时器setTimeout()
setTimeout()计时器,在载入后延迟指定时间后,去执行一次表达式,仅执行一次. 语法: setTimeout(代码,延迟时间); 参数说明: 1. 要调用的函数或要执行的代码串. 2. 延时时 ...
- C/S模型服务端vsftpd的安装与卸载
c/s模型 连接光驱DVD 设置环境(软件安装的环境) mkdir /mnt/yw----------------------(创建一个在mnt下yw目录) mount /dev.sr0 /mnt/y ...
- GPS获取坐标 显示Google map偏差计算
用手机获取GPS坐标 显示在手机地图偏差大约在100-200米左右,我把坐标放在 Maps.google.com 搜索坐标定位则相当精确. 可能是.....为了安全吧故意加的偏差 不过可以计算偏差使位 ...
- T-SQL 无参数的存储过程的创建和执行
use StudentManager go if exists(select * from sysobjects where name='usp_ScoreQuery') drop procedure ...
- YzmCMSV3.1 | 代码审计
YzmCMSV3.1 | 代码审计 这次审计 yzmcms . YzmCMS采用OOP(面向对象)方式自主开发的框架.框架易扩展,是一款高效开源的内容管理系统,产品基于PHP+Mysql架构,可运行在 ...