标签: properties-file

我如何使用或设置sonar-project.properties文件

我很少接触到SonarQube但都被要求做一个文件,解释如何设置/使用"sonar-project.properties文件".任何信息或输入将不胜感激.

properties-file sonar-runner sonarqube

14
推荐指数
2
解决办法
5万
查看次数

Spring中的Dynamic @ Value等价?

我有一个Spring管理的bean,使用property-placeholder其关联的a来加载属性context.xml:

<context:property-placeholder location="file:config/example.prefs" />
Run Code Online (Sandbox Code Playgroud)

我可以@Value在初始化时使用Spring的注释来访问属性,例如:

@Value("${some.prefs.key}")
String someProperty;
Run Code Online (Sandbox Code Playgroud)

...但我需要以通用方式将这些属性公开给其他(非Spring托管)对象.理想情况下,我可以通过以下方法公开它们:

public String getPropertyValue(String key) {
  @Value("${" + key + "}")
  String value;

  return value;
}
Run Code Online (Sandbox Code Playgroud)

...但显然我不能@Value在该上下文中使用注释.有没有什么方法可以example.prefs在运行时使用键访问Spring加载的属性,例如:

public String getPropertyValue(String key) {
  return SomeSpringContextOrEnvironmentObject.getValue(key);
}
Run Code Online (Sandbox Code Playgroud)

java spring properties-file

12
推荐指数
1
解决办法
1万
查看次数

在spring中写入/更新属性文件值

我有一些要求,我想在我使用my spring应用程序的属性文件中编写/更新值.

我用谷歌搜索了它,但我还没有找到使用Spring的直接方法.

有没有人知道如何做或有任何最好的方法来做到这一点.

提前致谢.

java spring properties-file

12
推荐指数
1
解决办法
1万
查看次数

以编程方式访问JSF应用程序中的属性文件

我试图访问我在代码中的JSF应用程序中使用的i18n属性文件.(这个想法是让一个页面显示其键和值实际上是一个表.)

该项目是一个maven项目,位于src/resources/localization文件夹中,并部署在WEB-INF\classes\localization \中的war文件中

java.util.Properties prop = new java.util.Properties();
String path = "localization/stat_codes.properties";
InputStream foo = prop.getClass().getResourceAsStream(path);
Run Code Online (Sandbox Code Playgroud)

但是无论我将路径变量设置为/WEB-INF/classes/localization/stat_codes.properties,"insetation.stat_codes.properties"等,变量foo都是null.类似的问题在这里,但是没有任何帮助也回答那里.

resources jsf internationalization properties-file

11
推荐指数
1
解决办法
5779
查看次数

如何从项目目录中读取javascript中的属性文件?

我正在构建Chrome打包应用程序.如果配置文件在资源目录中并且在启动时想要通过Javascript读取它,我想放置脚本配置.

例如

  • 项目
    • 网页内容
      • 的index.html
      • 的manifest.json
      • main.js
      • 资源
        • config.properties

在这里,我希望main.js在开头加载config.properties文件并获取键值对.

有没有人做过这样的事情?

javascript jquery filereader properties-file google-chrome-app

11
推荐指数
2
解决办法
8万
查看次数

Spring启动yml ResourceBundle文件

我正在使用MessageSourceSpring从.properties类路径中的文件加载错误消息.我的属性尊重某个"模板",例如{Object}.{field}.{unrespectedConstraint}:

userRegistrationDto.password.Size= Le mot de passe doit avoir au minimum 6 caractères.
userRegistrationDto.email.ValidEmail= Merci de saisir une addresse mail valide.
Run Code Online (Sandbox Code Playgroud)

在重构的情况下(例如,更改类的名称),我必须在几个地方更改我的属性文件.

有没有办法使用yaml文件(messages.yml)作为ResourceBundle来获取类似的东西:

userRegistrationDto:
  password:
    Size: Le mot de passe doit avoir au minimum 6 caractères.
  email:
    ValidEmail: Merci de saisir une addresse mail valide.
Run Code Online (Sandbox Code Playgroud)

spring resourcebundle properties-file spring-boot

11
推荐指数
2
解决办法
4333
查看次数

如何在springbean中注入完整的属性文件

我有一个包含很多值的属性文件,我不想单独列在我的bean-configuration文件中.例如:

<property name="foo">
    <value>${foo}</value>
</property>
<property name="bar">
    <value>${bar}</value>
</property>
Run Code Online (Sandbox Code Playgroud)

等等.

我想将所有完全注入java.util.Properties或更少注入java.util.Map.有办法吗?

resources spring properties-file

10
推荐指数
3
解决办法
2万
查看次数

Spring application.properties文件中的布尔值?

是否可以在Spring配置文件中使用布尔值?

我在我的bean中写了以下字段:

@Value("${pdk.populatedemo}")
private boolean populateDemo;
Run Code Online (Sandbox Code Playgroud)

但如果导致以下异常:

Could not autowire field: private boolean com.inthemoon.pdk.data.DatabaseService.populateDemo; nested exception is org.springframework.beans.TypeMismatchException: 
Failed to convert value of type [java.lang.String] to required type [boolean]; nested exception is java.lang.IllegalArgumentException: 
Invalid boolean value [1;]
Run Code Online (Sandbox Code Playgroud)

我试过这里

pdk.populatedemo=1;
Run Code Online (Sandbox Code Playgroud)

application.properties.我也尝试过=true其他一些.

java spring properties-file

10
推荐指数
1
解决办法
2万
查看次数

Spring @Value带注释的方法,当属性不可用时使用默认值

情况

我将.properties文件中的属性注入到使用@Value注释的字段中.但是,此属性提供敏感凭据,因此我将其从存储库中删除.我仍然希望如果有人想要运行项目并且没有.properties文件,其凭据将默认值设置为字段.

问题

即使我将默认值设置为字段本身,当.properties文件不存在时,我也会遇到异常:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxx': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'secret' in string value "${secret}"
Run Code Online (Sandbox Code Playgroud)

这是带注释的字段:

 @Value("${secret}")
 private String ldapSecret = "secret";
Run Code Online (Sandbox Code Playgroud)

我预计在这种情况下只会设置普通字符串"secret".

java spring spring-annotations properties-file spring-boot

10
推荐指数
2
解决办法
9925
查看次数

springcloud api gateway属性文件声明变量

我在 springboot 应用程序中有 application.yaml 如下

spring:
  cloud:
    gateway:
      routes:
      - id: pgService
        uri: http://localhost:2005/
        predicates:
        - Path=/employee/**
      - id: inMateService
        uri: http://localhost:2006/
        predicates:
        - Path=/consumer/**
Run Code Online (Sandbox Code Playgroud)

上述声明的变量是针对Spring Cloud Gateway的

我想在 application.properties 文件中声明这些相同的变量。我不想使用 yaml 文件。请帮助我实现这个目标谢谢

java properties-file microservices api-gateway spring-cloud-gateway

10
推荐指数
2
解决办法
3万
查看次数