[EN] Using ConfigProperty in Jakarta Microprofile

We are trying to convert small Spring app into Jakarta EE. In that process, I would like to share my exprience in a short format with you.  Let’s you have a property file in resources

 

 

In Spring Framework you can read and assign the key values in properties files like this :

@Value("${newfromconnectionscontroller.connectionsUrl}")
private String connectionsUrl;

@Value("${newfromconnectionscontroller.postsUrl}")
private String postsUrl;

What is the equivalent annotation in Jakarta EE ? Here is the answer :

  
@Inject
@ConfigProperty(name = "newfromconnectionscontroller.connectionsUrl")
  private String connectionsUrl;
  @Inject  
  @ConfigProperty(name = "newfromconnectionscontroller.postsUrl")
  private String postsUrl;

But you have to add org.eclipse.microprofile dependency into your pom.xml file

<dependency>
    <groupId>org.eclipse.microprofile</groupId>
    <artifactId>microprofile</artifactId>
    <version>1.3</version>
    <type>pom</type>
    <scope>provided</scope>
</dependency>

Bye !

No Comments

Post a Comment

Comment
Name
Email
Website