Is there a way to read text from external properties file in spring without using the @Value
annotation. Ex: application.properties
var.foo=\"he
You can use a placeholder when you declare a bean in your configuration file.Here you can try an example : https://www.mkyong.com/spring/spring-propertyplaceholderconfigurer-example/
Using the @Value("${property}")
annotation to inject configuration properties can sometimes be cumbersome, so spring boot introduced the @ConfigurationProperties
, this should be the solution what you want.
Here is the reference doc.
If you are using Spring Boot then you can try this method, without doing any special configuration
@environment.getProperty('property')
I don't think you can achieve this unless the underlying implementation of the annotations you're using either come with their own standard for i18n (like ValidationMessages.properties
), or support Spring's MessageSource
.
In the case of the latter alternative, all you should have to do is to add your key/value pairs inside a messages.properties
file and let the framework do the rest:
messages.properties
my.validation.error.message=Something went terribly wrong!
SomeClass.java
@MySpringCompatibleValidationAnnotation("my.validation.error.message")
private String someVariable;
Bottom line is, depending on the framework you're trying to use, it may or may not support this out-of-the-box.
Now, as far as Swagger goes, i18n support for documentation was proposed as a new feature, but it was shut down or put on hold while they put some more thought into how it should be implemented. See https://github.com/OAI/OpenAPI-Specification/issues/274 for more details.