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包之间 ...
随机推荐
- windows安装mysql数据库并修改密码
1.下载 MySQL Community Server https://dev.mysql.com/downloads/mysql/ 2.解压 如果想要让MySQL安装在指定目录,那么就将解压后的文件 ...
- DS二叉树--Huffman编码与解码
题目描述 1.问题描述 给定n个字符及其对应的权值,构造Huffman树,并进行huffman编码和译(解)码. 构造Huffman树时,要求左子树根的权值小于.等于右子树根的权值. 进行Huffma ...
- HTTP之Cookie
cookie是什么 浏览器存储在本地电脑上的一小段文本文件,cookie的存在主要是为了解决http协议无状态的问题,例如通过cookie来判断用户的登录状态,是否是某一个用户等. cookie的结构 ...
- 科学-天文学-天文观测站:TMT(红外天文望远镜)
ylbtech-科学-天文学-天文观测站:TMT(红外天文望远镜) 30米望远镜(Thirty Meter Telescope,TMT) 系由美国加州大学和加州理工学院负责研制的新一代地基巨型光学-红 ...
- 1122 Hamiltonian Cycle (25 分)
1122 Hamiltonian Cycle (25 分) The "Hamilton cycle problem" is to find a simple cycle that ...
- 用juniversalchardet解决爬虫乱码问题
爬虫往往会遇到乱码问题.最简单的方法是根据http的响应信息来获取编码信息.但如果对方网站的响应信息不包含编码信息或编码信息错误,那么爬虫取下来的信息就很可能是乱码. 好的解决办法是直接根据页面内容来 ...
- PDP context
PDP context[edit] The packet data protocol (PDP; e.g., IP, X.25, FrameRelay) context is a data struc ...
- CNN卷积层:ReLU函数
卷积层的非线性部分 一.ReLU定义 ReLU:全称 Rectified Linear Units)激活函数 定义 def relu(x): return x if x >0 else 0 #S ...
- Chapter3:Qt5布局管理
3.1分割窗口QSplitter类 QSplitter *splitterMain = new QSplitter(Qt::Horizontal,0); QTextEdit *textLeft = n ...
- synergy一个鼠标键盘控制多台电脑
有些时候我们同时操作多台电脑,但是我们只用一个鼠标和一个键盘,如果通过转换器啊或者是多个鼠标键盘就非常不方便了 下面我介绍一下通过安装synergy这个软件来给开发人员提供方便 这个软件安装比较简单, ...