Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e688ed0
commit cf05b3b
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?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>springboot</groupId> | ||
<artifactId>springboot-configuration</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>springboot-configuration :: 配置 Demo</name> | ||
|
||
<!-- Spring Boot 启动父依赖 --> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.5.1.RELEASE</version> | ||
</parent> | ||
|
||
<dependencies> | ||
<!-- Spring Boot web依赖 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<!-- Junit --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
19 changes: 19 additions & 0 deletions
19
springboot-configuration/src/main/java/org/spring/springboot/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.spring.springboot; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* Spring Boot 应用启动类 | ||
* | ||
*/ | ||
// Spring Boot 应用的标识 | ||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
// 程序启动入口 | ||
// 启动嵌入式的 Tomcat 并初始化 Spring 环境及其各 Spring 组件 | ||
SpringApplication.run(Application.class,args); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...ngboot-configuration/src/main/java/org/spring/springboot/config/MessageConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.spring.springboot.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* Created by bysocket on 08/09/2017. | ||
*/ | ||
@Configuration | ||
public class MessageConfiguration { | ||
|
||
@Bean | ||
public String message() { | ||
return "message configuration"; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ot-configuration/src/test/java/org/spring/springboot/config/MessageConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.spring.springboot.config; | ||
|
||
import org.junit.Test; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* Spring Boot MessageConfiguration 测试 - {@link MessageConfiguration} | ||
* | ||
*/ | ||
public class MessageConfigurationTest { | ||
|
||
@Test | ||
public void testGetMessageBean() throws Exception { | ||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MessageConfiguration.class); | ||
assertEquals("message configuration", ctx.getBean("message")); | ||
} | ||
|
||
@Test | ||
public void testScanPackages() throws Exception { | ||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); | ||
ctx.scan("org.spring.springboot"); | ||
ctx.refresh(); | ||
assertEquals("message configuration", ctx.getBean("message")); | ||
} | ||
} |