java - Application/Deployment specific properties with JAX-RS and WildFly -


i used spring on tomcat/jetty , work on existing jax-rs project running on wildfly (resteasy).

i know application/deployment property files go on wildfly, standalone/configuration/myapp.properties?

then how application load them? tried in our class extending javax.ws.rs.core.application:

@javax.ws.rs.applicationpath("") public class applicationconfig extends application {      @override     public map<string, object> getproperties() {         system.out.println(">>>>>>>>>>>>>>>> properties");         // added method nothing printed...     }      @override     public set<class<?>> getclasses() {         system.out.println(">>>>>>>>>>>>>>>> classes");         // printed         ...         // classes loaded correctly     } } 

then how access properties in controllers? way don't use dependency injection.

thanks!

some investigation...

normally should work

  1. the getproperties() should called on startup load required application properties.
  2. you should able inject javax.ws.rs.core.configuration resource classes (with @context) , retrieve properties through object. stated in javadoc

    this interface can injected using context annotation.

test

@applicationpath("/api") public class restapplication extends application {      @override     public map<string, object> getproperties() {         system.out.println(">>>>>>>>>>>>>>>> properties");         map<string, object> props = new hashmap<>();         props.put("message", "hello configuration properties!");         return props;     } }  @path("config") public class configresource {      @context     private configuration configuration;      @get     public response getproperty(@queryparam("prop") string prop) {         string propvalue = (string)configuration.getproperty(prop);         return response.ok(propvalue).build();     } } 

discoveries

  • the above doesn't work tested resteasy 3.0.9.final. error no context type. don't know why. might bug, don't know. maybe can into.
  • the above works fine jersey 2.16

what works resteasy

what could work resteasy inject application (as mentioned here resource (also @context) , properties way.

@path("config") public class configresource {      @context      application application;      @get     public response getproperty(@queryparam("prop") string prop) {         string propvalue = (string)application.getproperties().get(prop);         return response.ok(propvalue).build();     } } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -