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:

Springboot配置:
 
8、模块下载:下载
  
 

Spring Maven项目集成Springboot的更多相关文章

  1. [转帖]spring boot项目集成jacoco

    小试牛刀:spring boot项目集成jacoco 2019-03-28 20:14:36 zyq23333 阅读数 509   版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议, ...

  2. Spring Boot 项目集成 Alibaba Druid

    Druid 是一个非常好用的数据库连接池,但是他的好并不止体现在作为一个连接池加快数据访问性能上和连接管理上,他带有一个强大的监控工具:Druid Monitor.不仅可以监控数据源和慢查询,还可以监 ...

  3. 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 ...

  4. Spring boot项目集成Neo4j

    第一步,创建Springboot工程 使用Eclipse 创建Maven项目,并修改pom.xml文件为: <?xml version="1.0" encoding=&quo ...

  5. 通过idea 打包 spring maven项目打包为可执行jar包

    用assembly打包一直报错: shangyanshuodeMacBook-Pro:target shangyanshuo$ java -jar jobscrawler-1.0-SNAPSHOT-j ...

  6. Maven项目集成Jetty

    1.新建webapp maven项目. 项目目录结构如下. 2.pom文件添加jetty构建. <project xmlns="http://maven.apache.org/POM/ ...

  7. 测者的测试技术手册:自动化的自动化EvoSuite:Maven项目集成EvoSuite实战

    EvoSuite是由Sheffield等大学联合开发的一种开源工具,用于自动生成测试用例集,生成的测试用例均符合Junit的标准,可直接在Junit中运行.得到了Google和Yourkit的支持. ...

  8. 【Spring Boot&&Spring Cloud系列】Spring Boot项目集成Swagger UI

    前言 Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目标是使客户端和文件系统作为服务器以同样的速度来更新.文件的方法,参数和模型紧密集 ...

  9. spring maven项目解决依赖jar包版本冲突方案

    引入:http://blog.csdn.net/sanzhongguren/article/details/71191290 在spring reference中提到一个解决spring jar包之间 ...

随机推荐

  1. WPF Demo14 依赖属性

    using System.Windows; namespace DependencyPropertyDemo1 { public class Student:DependencyObject { pu ...

  2. table 设置每列的颜色

    ISBN Title Price 3476896 My first HTML $53 5869207 My first CSS $49   <!DOCTYPE html> <html ...

  3. ALGO-152_蓝桥杯_算法训练_8-2求完数

    记: 掌握完数的概念 AC代码: #include <stdio.h> int main(void) { int i,j,sum; ; i <= ; i ++) { sum = ; ...

  4. 廖雪峰Java4反射与泛型-1反射-2访问字段Field和3调用方法Method

    2.字段Field 2.1.通过Class实例获取字段field信息: getField(name): 获取某个public的field,包括父类 getDeclaredField(name): 获取 ...

  5. [UE4]嵌套Canvas

  6. SCCM2012 R2实战系列之十二:解决OSD分发时间过长的问题

    对于SCCM 2012 R2的初学者来说,能够成功分发操作系统可能已经是非常兴奋了.但在企业中会遇到客户提出的各种各样苛刻的需求.所以在平时实验过程中多站点客户的角度想问题,尽可能的贴近企业实际生产环 ...

  7. 第七章 :分布式监控与SNMP监控

    7.1 分布式监控 7.1.1 作用 分担压力,减轻负载 多机房监控 zabbix Server  ===>  zabbix agent (只能同一个局域网监控) 分担压力,降低负载 zabbi ...

  8. SAS 报表输出一些新式控制

    SAS 报表输出一些新式控制 *******************************:*Purpose: 报表*Programm: *Programmor: *Date: *Version: ...

  9. CRM 总是弹出登录窗口

    最近测试机总是会出现登录窗口,也能正常进入系统,但是会反复出现. 环境:CRM2016 问题:总是弹出登录窗口 解决方法:

  10. vue事件深入

    事件对象: @click="show($event)" ev.clientX---接收 事件冒泡: 阻止冒泡: 1. ev.cancelBubble=true; 2.@click. ...