我有这个 importResource @ImportResource({"classpath:spring/*/*.xml"})
我将根据 application.properties 文件中的值设置此路径
我可以传递 dev 或 prod,路径应该是 classpath:spring/dev/*.xml
或 classpath:spring/prod/*.xml
最佳答案
这样的事情应该有效:
在application.properties
my_profile=dev
然后将字符串参数添加到注释中:
@ImportResource({"classpath:spring/${my_profile}/*.xml"})
您可能还想了解 Spring 中配置文件的配置方式: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html
关于java - 如何根据 application.properties 文件动态设置 importResource 路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56345679/