1 banner 配置
1.1 關閉 banner
package com.tzb;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
@SpringBootApplication
public class SpringbootTestApplication {
public static void main(String[] args) {
// SpringApplication.run(SpringbootTestApplication.class, args);
// 關閉 bannner
SpringApplicationBuilder builder = new SpringApplicationBuilder(SpringbootTestApplication.class);
SpringApplication build = builder.build();
build.setBannerMode(Banner.Mode.OFF);
build.run(args);
}
}
2 tomcat 配置
2.1 如果不想用 tomcat
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
3 spring屬性注入
<dependency>
<!-- this is needed or IntelliJ gives junit.jar or junit-platform-launcher:1.3.2 not found errors -->
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
-
實體類
-
配置文件
-
測試類
@SpringBootTest
class SpringbootTestApplicationTests {
@Autowired
Book book;
@Test
void contextLoads() {
System.out.println("書籍信息: "+book);
}
}