springboot:配置ymlDidea.test.cyclic.buffer.size=1048576 “-javaagent:

3 篇文章 0 订阅
3 篇文章 0 订阅

1.创建yml-springboot

yml
yum2
yum3
yum4

2.application.properties配置端口

yum5
yum6

3.yml配置文件值注入

yum
yum
yum

person:
    lastName: hello
    age: 18
    boss: false
    birth: 2017/12/12
    maps: {k1: v1,k2: 12}
    lists:
      - lisi
      - zhaoliu
    dog:
      name: 小狗
      age: 12

4.需要安装配置文件处理器

yum

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.3.1.RELEASE</version>
      <relativePath/> <!-- lookup parent from repository -->
   </parent>
   <groupId>com.cevent</groupId>
   <artifactId>springboot-02-config</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <name>springboot-02-config</name>
   <description>Demo project for Spring Boot</description>

   <properties>
      <java.version>1.8</java.version>
   </properties>

   <dependencies>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-web</artifactId>
      </dependency>

      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-test</artifactId>
         <scope>test</scope>
         <exclusions>
            <exclusion>
               <groupId>org.junit.vintage</groupId>
               <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
         </exclusions>
      </dependency>
      <!--导入yml配置文件提示:配置文件处理器-->
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-configuration-processor</artifactId>
         <optional>true</optional>
      </dependency>
      <!--引入junit-->
<!--      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>4.12</version>
         <scope>test</scope>
      </dependency>-->
   </dependencies>

   <build>
      <plugins>
         <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
         </plugin>
      </plugins>
   </build>

</project>


5.自动生成的main class

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);
   }

}


6.person类

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<String,Object> maps;
    private List<Object> lists;

    private Dog dog;

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public boolean isBoss() {
        return boss;
    }

    public void setBoss(boolean boss) {
        this.boss = boss;
    }

    public Date getBirth() {
        return birth;
    }

    public void setBirth(Date birth) {
        this.birth = birth;
    }

    public Map<String, Object> getMaps() {
        return maps;
    }

    public void setMaps(Map<String, Object> maps) {
        this.maps = maps;
    }

    public List<Object> getLists() {
        return lists;
    }

    public void setLists(List<Object> lists) {
        this.lists = lists;
    }

    public Dog getDog() {
        return dog;
    }

    public void setDog(Dog dog) {
        this.dog = dog;
    }

    @Override
    public String toString() {
        return "Person{" +
                "lastName='" + lastName + '\'' +
                ", age=" + age +
                ", boss=" + boss +
                ", birth=" + birth +
                ", maps=" + maps +
                ", lists=" + lists +
                ", dog=" + dog +
                '}';
    }
}


7.dog类

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 +
                '}';
    }
}


8.yml配置

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


9.启动失败

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仓库,重新导包-不管用,但做错误记录】

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.3.1.RELEASE</version>
      <relativePath/> <!-- lookup parent from repository -->
   </parent>
   <groupId>com.cevent</groupId>
   <artifactId>springboot-02-config</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <name>springboot-02-config</name>
   <description>Demo project for Spring Boot</description>

   <properties>
      <java.version>1.8</java.version>
   </properties>

   <dependencies>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-web</artifactId>
      </dependency>

      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-test</artifactId>
         <scope>test</scope>
         <exclusions>
            <!--<exclusion>
               <groupId>org.junit.vintage</groupId>
               <artifactId>junit-vintage-engine</artifactId>
            </exclusion>-->
         </exclusions>
      </dependency>
      <!--导入yml配置文件提示:配置文件处理器-->
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-configuration-processor</artifactId>
         <optional>true</optional>
      </dependency>
      <!--引入junit-->
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>4.12</version>
         <scope>test</scope>
      </dependency>
   </dependencies>

   <build>
      <plugins>
         <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
         </plugin>
      </plugins>
   </build>

</project>


maven

10.只能升级idea,这里之前选用2017,现在使用2020版,安装如下

(1)官网下载
https://www.jetbrains.com/idea/download/other.html
idea
idea
(2)安装
1
2
3
4
5
(3)默认进入只能register,我们退出后进入原来的old版本,我之前安装的是2017
然后退出,再进入2020版
6
(4)弹出restart选项
7
(5)因为不是默认的C盘位置,jar包不管用,退出project,进入configure配置
idea
(6)修改agent
idea
(7)重启idea,进入register
idea
(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


(10)乱码解决
idea
11
(11)修改配置:重启生效

-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


properties
【原因:application.properties文件问题,yml不会报错】
idea

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值