父工程

idea点击spring-boot-starter-parent找到父工程spring-boot-dependencies模仿配置

  • 父工程
<?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> <groupId>com.fly</groupId>
<artifactId>SpringDemoRoot</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
  • 子工程
<?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> <groupId>com.fly</groupId>
<artifactId>SpringDemo</artifactId>
<version>1.0-SNAPSHOT</version> <parent>
<groupId>com.fly</groupId>
<artifactId>SpringDemoRoot</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>

SpringBoot整合测试

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
  • 测试
import com.fly.IndexController;
import junit.framework.TestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; @SpringBootTest(classes = IndexController.class)
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
public class TestIndexController {
@Autowired
private IndexController indexController; @Test
public void test1(){
//断言indexController的first()返回"hello:fly"
TestCase.assertEquals(this.indexController.first(),"hello:fly");
}
}

SpringBootApplication注解

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan; @EnableAutoConfiguration
@ComponentScan("com.fly")
public class SpringDemoApp {
public static void main(String[] args){
SpringApplication.run(SpringDemoApp.class,args);
}
}

使用组合注解SpringBootApplication注解:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan; //@EnableAutoConfiguration
//@ComponentScan("com.fly")
@SpringBootApplication(scanBasePackages = {"com.fly"})//默认是本包及子报
public class SpringDemoApp {
public static void main(String[] args){
SpringApplication.run(SpringDemoApp.class,args);
}
}

03.父工程pom、整合测试、SpringBootApplication注解的更多相关文章

  1. idea - maven子工程找不到父工程pom

    1.应该先构建父项目,再构建子项目.因为子项目依赖于父项目.即父项目先install到本地

  2. 父工程 pom版本

    <!-- 集中定义依赖版本号 --> <properties> <junit.version>4.12</junit.version> <spri ...

  3. springboot 创建子父工程

    1.创建子父工程 2.添加pom配置文件 2.1  父工程pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" ...

  4. 奥展项目笔记04--Spring cloud 通过父工程打包多个子工程,导出可运行的Jar包

    在spring cloud微服务搭建过程中,我们创建了多个微服务模块,如图: 1.父工程Pom文件 <?xml version="1.0" encoding="UT ...

  5. pom父工程dependencyManagement中的jar包在子工程中不写版本号无法引入的问题

    1.遇到的问题:  本人用的idea,然后在导入别人的项目的时候,pom文件中没有报错了,但是在maven栏目中jar包却一直报红,是因为我没写版本的原因吗?不对呀,我的父工程下已经写了springb ...

  6. JAVAEE——spring02:使用注解配置spring、sts插件、junit整合测试和aop演示

    一.使用注解配置spring 1.步骤 1.1 导包4+2+spring-aop 1.2 为主配置文件引入新的命名空间(约束) 1.3 开启使用注解代替配置文件 1.4 在类中使用注解完成配置 2.将 ...

  7. maven(二) maven项目构建ssh工程(父工程与子模块的拆分与聚合)

    前一节我们明白了maven是个什么玩意,这一节就来讲讲他的一个重要的应用场景,也就是通过maven将一个ssh项目分割为不同的几个部分独立开发,很重要,加油 --WH 一.maven父工程与子模块的拆 ...

  8. Maven聚合、Maven仓库jar包以及Spring+MyBatis+JUnit+Maven整合测试的搭建过程

    一.Maven将父项目创建到父项目的内部 在父项目的pom.xml上 点右键,选择maven-->new-->maven module  project 二.Maven聚合 在某个项目的p ...

  9. 转帖:maven(二) maven项目构建ssh工程(父工程与子模块的拆分与聚合)

    出处:http://www.cnblogs.com/whgk/p/7121336.html 前一节我们明白了maven是个什么玩意,这一节就来讲讲他的一个重要的应用场景,也就是通过maven将一个ss ...

随机推荐

  1. Aliyun mysql配置 远程访问 10038

    环境 centos7.2    mysql5.7 网上搜了好多的文章,有的说在/etc/my.cnf 注释掉bind-address = 127.0.0.1 ,也开启了3306端口的防火墙,也添加了远 ...

  2. vs报错 "多步操作产生错误。请检查每一步的状态值"

    今天在开发一个插件图表控件,在实例化后向数据库Update时候,报出此错误,刚开始以为是我用的异步方法,在调用程序的句柄的时候的线程问题,索性改成了同步方法,仍然报出此错误.后来Debug和排错,定位 ...

  3. 【ABAP系列】SAP ABAP 如何控制Dialog中的键盘(回车)功能

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP 如何控制Dia ...

  4. 【EWM系列】SAP EWM模块-修改任何内容都报错

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[EWM系列]SAP EWM模块-修改任何内容都 ...

  5. jmeter uniq 取值方式设置

  6. 微信、QQ、新浪微博等第三方登录,你想知道的都在这了(上) 微信、QQ、新浪微博等第三方登录,你想知道的都在这了(下)

    微信.QQ.新浪微博等第三方登录,你想知道的都在这了(上):https://www.jianshu.com/p/133d84042483 微信.QQ.新浪微博等第三方登录,你想知道的都在这了(下):h ...

  7. Flutter 仿滴滴出行App

    绿色出行 Flutter 仿滴滴出行App 地图:采用高德地图,仅简单完成了部分功能,基础地图,地址检索,逆地理编码. 界面:仿滴滴主界面,地图中心请求动效果,服务tabs展开效果,地址检索界面,城市 ...

  8. 使用redis来存储session,不同框架对session的命名规则是不一样的

    今天做了一个测试,在同一个云服务器上,搭建了两个server,其中一个是用laravel框架写的,另外一个使用原生php开发的,为了提高访问的速度,使用云服务器中的redis来存储session数据, ...

  9. 最长公共上升子序列 (LIS+LCS+记录)

    [题目描述] 给出两个序列,求出最长公共上升子序列的长度,并输出其中一个解. [题目链接] http://noi.openjudge.cn/ch0206/2000/ [算法] 经典问题,结合了LIS和 ...

  10. hdu 6301 Distinct Values (思维+set)

    hdu 6301 Distinct Values 题目传送门 题意: 给你m个区间,让你求出一个长度为n的区间且满足在这些区间的数不重复, 并且要求字典序最小 思路: 如果我们已经求出这个序列了,你会 ...