FHIR Chat · Need help in reading new properties in application.yaml · hapi

Stream: hapi

Topic: Need help in reading new properties in application.yaml


view this post on Zulip NARASIMHA MURTHY (Jan 19 2021 at 02:09):

Hi All,

I need help in reading new properties added in application.yaml file in hapi-fhir-jpaserver-starter 5.2.0.
I have added the following 2 additional properties in application.yaml file in hapi-fhir-jpaserver-starter 5.2.0.

oauth_certs_token_uri: http://localhost:8080/auth/realms/test/protocol/openid-connect/certs
oauth_expected_issuer: http://localhost:8080/auth/realms/test

Then I added variables for each property in AppProperties.Java
public class AppProperties
{
......
......
private String oauth_certs_token_uri;
private String oauth_expected_issuer;

.....
getters and setters for the same properties
}

Next, I created a new class called MyUtils
package ca.uhn.fhir.jpa.starter.mycompany.utils
Class MyUtils
{
@Autowired
AppProperties appproperties;

public void ReadValues()
{
System.out.println(appproperties.getOauth_certs_token_uri);
System.out.println(appproperties.getOauth_expected_issuer);
}
}

My autowired appproperties value is null. I also tried to read using @Value annotation still the property value is coming as null.

I have tried various combinations of @ComponentScan by giving the base package name as ca.uhn.fhir.jpa.starter.mycompany in the application.java main class. But it gave runtime errors.

I have wasted lot of time in resolving this issue. Please help me resolve this issue by providing the steps required to read new properties in YAML file in case of HAPI FHIR 5.2.0 release.
Thanks in advance for your help.

view this post on Zulip Jens Villadsen (Jan 26 2021 at 13:02):

image.png

view this post on Zulip Jens Villadsen (Jan 26 2021 at 13:02):

It works fine ... - you have however not injected the class AuthorizationTokenHelperanywhere @NARASIMHA MURTHY

view this post on Zulip Jens Villadsen (Jan 26 2021 at 13:03):

just inject it into eg. the BaseJpaRestfulServer

view this post on Zulip Jens Villadsen (Jan 26 2021 at 13:03):

image.png

view this post on Zulip NARASIMHA MURTHY (Jan 26 2021 at 14:54):

Hi Jens,

THanks a lot for your help. But I want to create a new class called MyCompanyClass under a new package and wants to inject AuthorizationTokenHelper into that new class. How could I achieve the same.
I am sorry I did not mention this the first time.

Thanks in advance.
thanks,
Narasimha

view this post on Zulip NARASIMHA MURTHY (Jan 26 2021 at 17:18):

@Jens Villadsen I figured out how to do that. Thanks a lot for your help.


Last updated: Apr 12 2022 at 19:14 UTC