第一章
(一)多模塊項目搭建:
1)注意有沒有版本號不一致得情況
2)pom文件里面得繼承關系。
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>yingxue-web</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>yingxue-service</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
project.version是整個項目得版本
parent.version是父模塊得版本
沒 掃描到要去掃描包:
@SpringBootApplication(scanBasePackages = "com.yingxue.lesson") public class SpringBootWebApplication { public static void main(String[] args) { SpringApplication.run(SpringBootWebApplication.class,args); } }
在serviceImpl上要加@Service注入到容器里。才能讓別人用。
在yml配置文件里面list前面需要用-空格寫list,并且下一行起。
server: port: 8083 person: username: zhangsan age: 22 salary: 20002 sex: male pets: dofg,cat friend: x: per y: son list: - app - lica - tion children: - k: con v: vertible - k: hggjsf v: dsagfgd employee: name: along age: 22
用配置文件給復雜得結構賦值得時候需要
簡單配置文件讀取和復雜配置文件讀取
簡單文件需要自己寫config來做映射,復雜文件需要用@ConfigurationProperties。
@ConfigurationProperties(prefix = "person")//person這個地方得名字要與配置文件里面得一致,因為去讀得就是配置文件里得
@Component//這個要有,這個是將這個類注入容器得注解。否則讀不到
public class Person {
private String username;
private double salary;
private int age;
private String sex;
private String[] pets;
多環(huán)境配置的關鍵語句是:
spring.profiles.active=dev/prod/test等不同的環(huán)境的配置文件
還有關鍵的運行jar的語句:
java -jar springboot-profile-0.0.1-SNAPSHOT.jar --spring.profiles.active=test//后面是那個環(huán)境寫那個環(huán)境
springboot單元測試
along

浙公網(wǎng)安備 33010602011771號