03.父工程pom、整合测试、SpringBootApplication注解
父工程
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注解的更多相关文章
- idea - maven子工程找不到父工程pom
1.应该先构建父项目,再构建子项目.因为子项目依赖于父项目.即父项目先install到本地
- 父工程 pom版本
<!-- 集中定义依赖版本号 --> <properties> <junit.version>4.12</junit.version> <spri ...
- springboot 创建子父工程
1.创建子父工程 2.添加pom配置文件 2.1 父工程pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" ...
- 奥展项目笔记04--Spring cloud 通过父工程打包多个子工程,导出可运行的Jar包
在spring cloud微服务搭建过程中,我们创建了多个微服务模块,如图: 1.父工程Pom文件 <?xml version="1.0" encoding="UT ...
- pom父工程dependencyManagement中的jar包在子工程中不写版本号无法引入的问题
1.遇到的问题: 本人用的idea,然后在导入别人的项目的时候,pom文件中没有报错了,但是在maven栏目中jar包却一直报红,是因为我没写版本的原因吗?不对呀,我的父工程下已经写了springb ...
- JAVAEE——spring02:使用注解配置spring、sts插件、junit整合测试和aop演示
一.使用注解配置spring 1.步骤 1.1 导包4+2+spring-aop 1.2 为主配置文件引入新的命名空间(约束) 1.3 开启使用注解代替配置文件 1.4 在类中使用注解完成配置 2.将 ...
- maven(二) maven项目构建ssh工程(父工程与子模块的拆分与聚合)
前一节我们明白了maven是个什么玩意,这一节就来讲讲他的一个重要的应用场景,也就是通过maven将一个ssh项目分割为不同的几个部分独立开发,很重要,加油 --WH 一.maven父工程与子模块的拆 ...
- Maven聚合、Maven仓库jar包以及Spring+MyBatis+JUnit+Maven整合测试的搭建过程
一.Maven将父项目创建到父项目的内部 在父项目的pom.xml上 点右键,选择maven-->new-->maven module project 二.Maven聚合 在某个项目的p ...
- 转帖:maven(二) maven项目构建ssh工程(父工程与子模块的拆分与聚合)
出处:http://www.cnblogs.com/whgk/p/7121336.html 前一节我们明白了maven是个什么玩意,这一节就来讲讲他的一个重要的应用场景,也就是通过maven将一个ss ...
随机推荐
- C#中给RICHTEXTBOX加上背景图片
在系统自带的RichTextBox中是无法给它设置背景图片,但是我们在某些场合可能需要给RichTextBox设置背景图片.那么怎么实现这一想法呢?经过研究发现通过其它巧妙的途径可以给RichText ...
- 20180816-Java 多态
Java 多态 多态是同一个行为具有多个不同表现形式或形态的能力. 多态性是对象多种表现形式的体现. 比如我们说"宠物"这个对象,它就有很多不同的表达或实现,比如有小猫.小狗.蜥蜴 ...
- Visual Studio Code-使用Chrome Debugging for VS Code调试JS
准备工作 安装 Debugger for Chrome 插件 按 F5(或选择菜单栏的 Debug->Start Debuging),然后选择 Chrome,就会自动创建默认的配置文件 &quo ...
- Learn Python the hard way, ex40 字典,可爱的字典
#!/usr/bin/python #coding:utf-8 cities ={'CA':'sf','MI':'dt','FL':'je'} #创建字典 cities['NY']='ny' #增加新 ...
- BigDecimal保留小数处理
最近在处理支付相关的需求,涉及到金额的问题,采用传统的基本数据类型处理会存在误差,因此采用BigDecimal对象进行处理. 一.构造BigDecimal对象的方式 BigDecimal(int) ...
- 题解1235. 洪水 (Standard IO)
Description 一天, 一个画家在森林里写生,突然爆发了山洪,他需要尽快返回住所中,那里是安全的.森林的地图由R行C列组成,空白区域用点“.”表示,洪水的区域用“*”表示,而岩石用“X”表示, ...
- MapReduce(3): Partitioner, Combiner and Shuffling
Partitioner: Partitioning and Combining take place between Map and Reduce phases. It is to club the ...
- 高德WMTS规则
新版 http://wprd0{1-4}.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1& ...
- Rsync+inotify搭建使用
## Rsync搭建 ### 1.1 环境准备 ``` Rsync-Server 192.168.1.174 Client-Rsync 192.168.1.173 服务启动用户都是root,客户端的用 ...
- CSS基础--属性选择器、伪类选择器
属性选择器 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...