“Application.yml参数注入到数组”的版本间的差异

来自姬鸿昌的知识库
跳到导航 跳到搜索
第7行: 第7行:
 
   - E:\record\2023
 
   - E:\record\2023
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
 +
  
 
==== Application.java ====
 
==== Application.java ====

2023年1月26日 (四) 10:14的版本

首先,因为 @Value 的实现机制,下面这种注入是不支持的

application.yml

include:
  - E:\record\2022
  - E:\record\2023



Application.java

@SpringBootApplication
@Slf4j
@Data
public class Application implements CommandLineRunner {

    @Value("${include}")
    String[] include;

    public static void main(String[] args) {
        log.info("STARTING THE APPLICATION");
        SpringApplication.run(Application.class, args);
        log.info("APPLICATION FINISHED");
    }

    @Override
    public void run(String... args) {

        for (String str:include) {
            log.info(str);
        }
        
    }

}