Springboot reads the properties custom configuration file

Why choose to update today, because it's on a whim. Don't ask why. Asking is that I forgot Then I spent more time today to Baidu others' wrong method, which made my scalp numb Produced by yourself is a fine product suitable for you

1. Create a new spring boot project

In the next step, you do not need to add any dependencies, and you can directly complete the creation

2. Then add the following dependencies to the POM file

 <!-- springboot configuration依赖 -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-configuration-processor</artifactId>
      <optional>true</optional>
    </dependency>

	<dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
    </dependency>

3. Then create a new properties file here

#用户名
config.username=金圣聪
#密码
config.password=123456

4. Then create a new class here

5. Then do unit test

In addition, Autowired can also be used here

The difference between the two

In this way, you can configure it where you need it, and it's much more convenient when you want to use it Especially when the test is different from the real address, hard coding should be avoided as much as possible

Good night, go to bed early

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>