父工程

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. vue项目适应不同屏幕做的适配器

    一般宽度是1920的,但是有的电脑屏幕很窄,导致页面样式错乱,那么可以设置app.vue以及主页面里的样式宽度为1920px,超过了就auto. 如下: (app.vue) (home.vue) 原效 ...

  2. vue中操作Dom节点的方法

    1.vue中ref操作dom节点 <template> <div id="app"> <div </div> <button @cl ...

  3. tomcat配置解决乱码问题

    在服务器上,如果项目是Tomcat启动的,可以用以下方式的设置解决乱码问题: 方法1.在Tomcat的catalina.sh(或者catalina.bat)文件中,开头加入: set JAVA_OPT ...

  4. wl

    <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Conten ...

  5. Jsoup获取DOM元素

    (1)doc.getElementsByTag(String tagName); (2)doc.getElementById(String id); (3)doc.getElementsByClass ...

  6. leetcode 78. 子集(c++)

    给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明:解集不能包含重复的子集. 示例: 输入: nums = [1,2,3]输出:[ [3],  [1],  [2],  ...

  7. 《图解设计模式》读书笔记1-1 Iterator模式

    目录 迭代器模式的类图 类图的解释 迭代器模式的代码 解释 原因 思想 迭代器模式的类图 类图的解释 名称 说明 Aggregate 集合接口,有提供迭代器的方法 Iterator 迭代器接口,提供迭 ...

  8. Unity 带骨骼的人体模型换装

    直入主题: 1.实验材料 两个模型,虽然缺胳膊少腿的,但是能用!!! 2.条件 两个模型在制作时是基于同一套骨骼,导出模型部位时连着该部位的骨骼一起导出,这样导入到Unity的模型就带有Skinned ...

  9. 网络流强化-HDU2732

    第一次遇到加了“多余”的边会导致WA的——在我看来是很多余,见代码191行 之后会思考为什么,想出来再更. 问题弄明白了,如果你在连接边连了一条到没有柱子的点的边,这个没有柱子的点是不可能连到终点的, ...

  10. Git007--删除文件

    Git--删除文件 本文来自于:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/ ...