我在JSR303和特殊的Hibernate-Validator中遇到问题.
我想从属性文件中读取验证消息.此属性文件位于部署到servlet容器的war文件中.问题是,它没有被访问.我有以下项目结构.
如何访问ValidationMessages.properties?或者这不可能吗?
除此之外,如果Hibernate-Validator首先在战争中读取属性文件并且如果它找不到密钥,那么它将是完美的,然后从jar中读取属性文件,依此类推.
属性文件可以有任何文件扩展名,比如.txt
?或者他们只能正常工作.properties
?我可以使用自定义文件扩展名.foo
吗?
我正在尝试从文本文件加载一个属性,但重音字符(saül)有一个不同的编码,而不是UTF-8如何避免它?
我的属性文件有一个带有重音字符的属性(saül).然而,当我远程调试时,我发现了properties.load(bufferedReader); 把它当作saül所以当我写入另一个文件时它被写成saül,我在应用程序的其他地方都有UTF-8编码.从文件中读取属性时,我不确定我做错了什么.
try {
final String propertyFilePath = System.getProperty(JVM_ARGUMENT_NAME);
if (StringUtils.hasText(propertyFilePath)) {
setLocalOverride(true);
resource = getApplicationContext().getResource(propertyFilePath);
BufferedReader bufferedReader =
new BufferedReader(new InputStreamReader(new FileInputStream(propertyFilePath), "UTF8"));
properties.load(bufferedReader);
externalFilePasswordConfigurer.afterPasswordPropertiesSet(properties);
LOGGER.info("ExternalFilePropertyConfigurer UTF-8 Reader");
}
setProperties(properties);
logProperties(properties);
} catch (Exception e) {
LOGGER.error("ExternalFilePropertyConfigurer setter failed to set properties: ", e);
throw new RuntimeException(e);
}
Run Code Online (Sandbox Code Playgroud) 我的组件库目录树设置如下:
resources
mylib
css
mycomponent.css
properties
mycomponent.properties
mycomponent.xhtml
Run Code Online (Sandbox Code Playgroud)
我想加载 mycomponent.xhtml 中的属性文件以用于消息。这样做的正确方法是什么?是否有 f:loadbundle 类型的解决方案?
propertyOne=1
propertyTwo=a/b
propertyThree=three
Run Code Online (Sandbox Code Playgroud)
如何将属性文件的内容更改为以下模式?
propertyThree 将在末尾添加一个字符串
propertyOne=apple/1
propertyTwo=a/and/b
propertyThree=three/end
Run Code Online (Sandbox Code Playgroud)我尝试使用,sed -i -e
但只有对每一行的更改进行硬编码才能成功;任何改进代码的建议?
sed -i -e '/propertyTwo=/ s=.*/=one/2/two' path/to/file
Run Code Online (Sandbox Code Playgroud) 我无法从我的环境变量中获取值。有很多类似的问题。但是NONE他们的工作对我来说
应用程序属性
spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=${SPRING_DATASOURCE_USERNAME}
spring.datasource.password=${SPRING_DATASOURCE_PASSWORD}
Run Code Online (Sandbox Code Playgroud)
系统变量
Variable name : SPRING_DATASOURCE_USERNAME
Variable Value : dbuser
Variable name : SPRING_DATASOURCE_PASSWORD
Variable Value : 123456789
Run Code Online (Sandbox Code Playgroud)
错误
invalid username/password; logon denied
Run Code Online (Sandbox Code Playgroud)
但是当我对其进行硬编码时,它工作正常。
更新
我的问题似乎很简单,但我找不到实现它的方法。
考虑以下情况:
prop1 = value1
prop2 = value2
prop3 = value3
prop4 = value2 (Value same as prop2)
prop5 = value3 (Value same as prop3)
Run Code Online (Sandbox Code Playgroud)
如何重用值 2 和 3(这些实际上是数据库特定的属性),因为我希望用户只提供一次而不是重复它。
谢谢。
案例 1:我将详细说明我的案例如下:我有两个属性文件 -application.properties
和quartz.properties
.
应用程序属性:
prop1 = value1
prop2 = value2
prop3 = value3
Run Code Online (Sandbox Code Playgroud)
石英属性
prop4 = value2 (Value same as prop2)
prop5 = value3 (Value same as prop3)
Run Code Online (Sandbox Code Playgroud)
请注意:我无法合并两个属性文件的内容,并且出于某种原因将它们分开放置。
在正常情况下,我希望 ${} 可以工作,但是当属性位于两个不同的文件中时,我猜它不起作用。
案例 2:[简单场景] 我尝试只使用一个 application.properties。但即便如此,我也无法在同一属性文件中重用属性值。
我的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> …
Run Code Online (Sandbox Code Playgroud) 我想要一个像下面这样的属性,它是地图
propertymap = {
key1:'{subkey1:'subvalue1',subkey2:'subvalue2'}',
key2:'{subkey3:'subvalue3',subkey4:'subvalue4'}' }
@Value("#{${propertymap}}")
private Map<String,Map<String,String>> propertymap;
Run Code Online (Sandbox Code Playgroud)
在我的配置类中使用了类似上面的代码,但出现错误。请让我知道是否有办法做到这一点。
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.util.Map nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelParseException: EL1043E:(pos 17): Unexpected token. Expected 'rcurly(})' but was 'identifier'
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
Run Code Online (Sandbox Code Playgroud) 我们有 2 个配置文件:一个在我们的 Spring Boot 应用程序(application.properties)中,另一个在我们的 ReactJs 应用程序中(我们在 create-react-app 中使用 .env)。决定在 ReactJs 应用程序中也使用 Spring Boot application.properties。谁能指导我如何实现这一目标?我已经阅读了“properties-reader”并尝试使用它,但我的 ReactJs 应用程序中没有 webpack.config.js 文件。
最近我将核心servlet应用程序的核心功能分成了一个jar文件.此jar文件现在部署在tomcat的lib文件夹中,应用程序(即servlets,jsps,properties files..etc)作为war文件独立部署.
jar文件需要特定的属性文件.我将这些属性文件放在war文件中的"src"文件夹下(即类层次结构的顶部).
在过去,当所有东西都在同一个项目中并部署在一个war文件中时.相关类可以访问属性文件.现在,当这些类部署在jar中时,它们无法看到war文件中的属性文件(即已部署的Web应用程序).
我在这里可以缺少什么?我如何加载proeprties文件的示例:
properties.load(getClass().getResourceAsStream("/appconfig.properties"));
Run Code Online (Sandbox Code Playgroud)
感谢您的时间.
properties-file ×10
java ×5
spring ×3
spring-boot ×3
bash ×1
classpath ×1
config ×1
jsf ×1
reactjs ×1
spring-mvc ×1
tomcat ×1
utf-8 ×1