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包之间 ...
随机推荐
- 黄聪: $(document).click() 在iphone上不触发事件解决办法
解决方案:加上 touchstart 事件 $(document).on(“click touchstart”, “.name”, function() { alert(“name”); });
- 同台同时多开DELPHI2007的解决办法
Cannot create file "C:\Users\Administrator\AppData\Local\Temp\EditorLineEnds.ttr"这个问题的产生根据 ...
- 【springBoot】之定制Banner
springboot启动时控制台打印图案如下: 1.假如我们不想看到这个图案 public static void main(String[] args) { SpringApplication ap ...
- Elasticsearch 5.2.x 使用 Head 插件连接不上集群
如果访问elasticsearch出现跨域的问题,如下: 修改elasticsearch.yml文件 vim $ES_HOME$/config/elasticsearch.yml # 增加如下字段 h ...
- windows修改远程桌面端口3389
regedit 按照路径打开,HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-T ...
- Hive深入学习--应用场景及架构原理
Hive背景介绍 Hive最初是Facebook为了满足对海量社交网络数据的管理和机器学习的需求而产生和发展的.互联网现在进入了大数据时代,大数据是现在互联网的趋势,而hadoop就是大数据时代里的核 ...
- 给VMware下的Linux扩容磁盘空间到根分区(以centos7.0为例)
一.扩展VMWare硬盘空间 关闭Vmware 的 Linux系统,这样,才能在VMWare菜单中设置: VM -> Settings... -> Hardware -> Hard ...
- Linux创建桥接网络
图形化创建 #nm-connection-editor & 选择桥接 设置桥接网络 点击添加 模式选择以太网 添加上行网卡 # brctl show 删除桥接 # nmcli connecti ...
- 如何获取阿里云OSS上每个文件夹的大小
原文 https://help.aliyun.com/document_detail/88458.html?spm=a2c4g.11186623.2.11.792462b15oU02q OSS文件按照 ...
- java打印实心10*10正方形, 空心10*10正方形
public class PrintSquare { public static void main(String[] args) { printSolidSquare(10); System.out ...