person:
lastName: hello
age: 18
boss: false
birth: 2017/12/12
maps: {k1: v1,k2: 12}
lists:
- lisi
- zhaoliu
dog:
name: 小狗
age: 12
"1.0" encoding="UTF-8"?>
"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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0</modelVersion>
org.springframework.boot</groupId>
spring-boot-starter-parent</artifactId>
2.3.1.RELEASE</version>
/> <!-- lookup parent from repository -->
</parent>
com.cevent</groupId>
springboot-02-config</artifactId>
0.0.1-SNAPSHOT</version>
springboot-02-config</name>
Demo project for Spring Boot</description>
.version>1.8</java.version>
</properties>
org.springframework.boot</groupId>
spring-boot-starter-web</artifactId>
</dependency>
org.springframework.boot</groupId>
spring-boot-starter-test</artifactId>
test</scope>
org.junit.vintage</groupId>
junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--导入yml配置文件提示:配置文件处理器-->
org.springframework.boot</groupId>
spring-boot-configuration-processor</artifactId>
true</optional>
</dependency>
<!--引入junit-->
<!--
junit</groupId>
junit</artifactId>
4.12</version>
test</scope>
</dependency>-->
</dependencies>
org.springframework.boot</groupId>
spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.cevent.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Springboot02ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(Springboot02ConfigApplication.class, args);
}
}
package com.cevent.springboot.bean;/**
* Created by Cevent on 2020/7/6.
*/
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @author cevent
* @description
* @date 2020/7/6 11:27
*/
//将application.yml配置的属性映射到Person,需要加入prefix="配置文件内的属性名"
//只有这个@ConfigurationProperties组件是容器中的组件,才能提供功能@Component
@Component
@ConfigurationProperties(prefix = "person")
public class Person {
private String lastName;
private Integer age;
private boolean boss;
private Date birth;
private Map,Object> maps;
private List
package com.cevent.springboot.bean;/**
* Created by Cevent on 2020/7/6.
*/
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @author cevent
* @description
* @date 2020/7/6 11:44
*/
public class Dog {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "Dog{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}
server:
port: 8082
person:
lastName: cevent
age: 28
boss: false
birth: 1992/11/22
maps: {k1: cevent1,k2: echo1}
lists:
- kakaxi
- mingren
dog:
name: 鲁班
age: 2
C:\JAVA\JDK\bin\java -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\DevTools\IntelliJ IDEA
….. com.intellij.rt.execution.junit.JUnitStarter
-ideVersion5 -junit5 com.cevent.springboot.Springboot02ConfigApplicationTests,contextLoads
Exception in thread "main"
java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()Ljava/lang/ClassLoader;
at org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry.loadTestEngines(ServiceLoaderTestEngineRegistry.java:30)
at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:53)
at com.intellij.junit5.JUnit5IdeaTestRunner.createListeners(JUnit5IdeaTestRunner.java:39)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:49)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
更换为本地maven仓库,重新导包-不管用,但做错误记录】
"1.0" encoding="UTF-8"?>
"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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0</modelVersion>
org.springframework.boot</groupId>
spring-boot-starter-parent</artifactId>
2.3.1.RELEASE</version>
/> <!-- lookup parent from repository -->
</parent>
com.cevent</groupId>
springboot-02-config</artifactId>
0.0.1-SNAPSHOT</version>
springboot-02-config</name>
Demo project for Spring Boot</description>
.version>1.8</java.version>
</properties>
org.springframework.boot</groupId>
spring-boot-starter-web</artifactId>
</dependency>
org.springframework.boot</groupId>
spring-boot-starter-test</artifactId>
test</scope>
<!--
org.junit.vintage</groupId>
junit-vintage-engine</artifactId>
</exclusion>-->
</exclusions>
</dependency>
<!--导入yml配置文件提示:配置文件处理器-->
org.springframework.boot</groupId>
spring-boot-configuration-processor</artifactId>
true</optional>
</dependency>
<!--引入junit-->
junit</groupId>
junit</artifactId>
4.12</version>
test</scope>
</dependency>
</dependencies>
org.springframework.boot</groupId>
spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
(1)官网下载
https://www.jetbrains.com/idea/download/other.html
(2)安装
(3)默认进入只能register,我们退出后进入原来的old版本,我之前安装的是2017
然后退出,再进入2020版
(4)弹出restart选项
(5)因为不是默认的C盘位置,jar包不管用,退出project,进入configure配置
(6)修改agent
(7)重启idea,进入register
(9)执行项目
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.1.RELEASE)
2020-07-06 23:16:57.428 INFO 40172 --- [ main] c.c.s.Springboot02ConfigApplicationTests : Starting Springboot02ConfigApplicationTests on LAPTOP-CQRDCFKL with PID 40172 (started by asus in D:\DEV_CODE\Intelligy_idead_code\spring\springboot\springboot-02-config)
2020-07-06 23:16:57.429 INFO 40172 --- [ main] c.c.s.Springboot02ConfigApplicationTests : No active profile set, falling back to default profiles: default
2020-07-06 23:16:58.244 INFO 40172 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-07-06 23:16:58.450 INFO 40172 --- [ main] c.c.s.Springboot02ConfigApplicationTests : Started Springboot02ConfigApplicationTests in 1.317 seconds (JVM running for 2.278)
Person{lastName='cevent', age=28, boss=false, birth=Sun Nov 22 00:00:00 CST 1992, maps={k1=cevent1, k2=echo1}, lists=[kakaxi, mingren], dog=Dog{name='鲁班', age=2}}
2020-07-06 23:16:58.608 INFO 40172 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
Process finished with exit code 0
(9)配置properties
# server.port=8081
# idea默认支持utf-8 properties默认支持ASCii编码
# 设置personֵ
person.last-name=cevent
person.age=28
person.birth=1992/07/06
person.boss=false
person.maps.k1=key1
person.maps.k2=haha
person.lists=kakaxi,luban,xiaofengxian
person.dog.name=dogger
person.dog.age=188
-Xms128m
-Xmx2048m
-XX:ReservedCodeCacheSize=240m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-ea
-XX:CICompilerCount=2
-Dsun.io.useCanonPrefixCache=false
-Djdk.http.auth.tunneling.disabledSchemes=""
-XX:+HeapDumpOnOutOfMemoryError
-XX:-OmitStackTraceInFastThrow
-Djdk.attach.allowAttachSelf=true
-Dkotlinx.coroutines.debug=off
-Djdk.module.illegalAccess.silent=true
#-javaagent:C:\Users\Public\.jetbrains\jetbrains-agent-v3.2.0.de72.619
-javaagent:D:\DEV\IntelligyIdea2020\jetbrains-agent.jar
-Dfile.encoding=UTF-8