小编d-s*_*uer的帖子

如何使用Spring @Value从java属性文件中填充HashMap

是否可以使用Spring @Value将属性文件中的值映射到HashMap.

目前我有类似的东西,映射一个值不是问题.但我需要在HashMap过期中映射自定义值.这样的事情可能吗?

@Service
@PropertySource(value = "classpath:my_service.properties")
public class SomeServiceImpl implements SomeService {


    @Value("#{conf['service.cache']}")
    private final boolean useCache = false;

    @Value("#{conf['service.expiration.[<custom name>]']}")
    private final HashMap<String, String> expirations = new HashMap<String, String>();
Run Code Online (Sandbox Code Playgroud)

属性文件:'my_service.properties'

service.cache=true
service.expiration.name1=100
service.expiration.name2=20
Run Code Online (Sandbox Code Playgroud)

像这个键映射是否可行:值集

  • name1 = 100

  • name2 = 20

java spring spring-el properties-file

36
推荐指数
5
解决办法
6万
查看次数

Gradle SpringDependencyManager从BOM定义中排除模块

我正在使用Gradle Spring 依赖项管理器插件在项目中导入Maven BOM定义。我需要排除BOM中定义的一个模块。

做这样的事情会很好,但是mavenBom只接受字符串。

dependencyManagement {
     imports {
          mavenBom ('io.spring.platform:platform-bom:1.0.1.RELEASE') {
              exclude 'com.datastax.cassandra:cassandra-driver-dse'
          }
     }
}
Run Code Online (Sandbox Code Playgroud)

是否可以通过其他方式排除BOM中定义的特定模块?

java spring dependency-management gradle gradle-plugin

5
推荐指数
1
解决办法
442
查看次数