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. Excel操作小结

    插入下拉选择(例如类型):选中单元格==>数据有效性==>数据有效性==>设置/有效性条件==>系列(下拉框内容用英文逗号分开): 插入下拉框设置不同背景色:选择需要设置的单元 ...

  2. 在CAD二次开发中使用状态条按钮

    Pane pane = new Pane(); pane.Enabled = true; pane.Text = "状态条按钮"; pane.ToolTipText = " ...

  3. 【rabbitmq】rabbitmq概念解析--消息确认--示例程序

    概述 本示例程序全部来自rabbitmq官方示例程序,rabbitmq-demo: 官方共有6个demo,针对不同的语言(如 C#,Java,Spring-AMQP等),都有不同的示例程序: 本示例程 ...

  4. Shader-另类实现

    利用Panel的Clipping 裁剪模式(其实该实现方式也是shader)主要是修改 centX 与 Size就ok的 . panel.baseClipRegion=new Vector4(cenX ...

  5. uoj#274. 【清华集训2016】温暖会指引我们前行

    http://uoj.ac/problem/274 由于边权互不相同,只需用lct维护带加边的最大生成树 #include<bits/stdc++.h> #define lc ch][0 ...

  6. P3811 乘法逆元

    传送 乘法逆元:ax ≡ 1 (mod p),其中x为a的逆元,求模意义下的乘法逆元,通常有一下几种方法: 1.拓展欧几里得(也就是exgcd) ax ≡ 1 (mod p) ax-py=1 这就变成 ...

  7. P2670扫雷

    链接 这是一个并不像搜索的题(其实它是个循环) 对于输入的a数组,一个一个遍历下来,如果a[i][j]是雷,那(i,j)周围8个点对应的位置雷数就+1(用b数组记录),注意不能超出边界,输出时,如果a ...

  8. java设计模式-Observe

    一.背景 请模拟下面情形: 小孩在睡觉,醒来后要求吃东西   代码: class Child{ private boolean wakenUp = false; void wakeUp(){ wake ...

  9. js中事件三阶段

    js中事件三阶段 先贴代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...

  10. Java-Runoob-高级教程-实例-方法:10. Java 实例 – 标签(Label)

    ylbtech-Java-Runoob-高级教程-实例-方法:10. Java 实例 – 标签(Label) 1.返回顶部 1. Java 实例 - 标签(Label)  Java 实例 Java 中 ...