java - Load property values with @Value in WildflyServer not work -
i have property file, configurationservices.properties, content:
formatonombreserie=1.2_3
and want load property inside webapp so:
i have class
@configuration @componentscan(basepackages = { "co.com.*" }) @propertysource("classpath:configurationservices.properties") public class configuracion { @value("${formatonombreserie}") public void setfileproperty(string aformatonombreserie) { system.out.println("directo en el set: " + aformatonombreserie); configuracion.aformatonombreserie = aformatonombreserie; } private static string aformatonombreserie; ......... public static string getpropiedad(string name) { switch (name) { case "formatonombreserie": return aformatonombreserie; ......... } @bean public static propertysourcesplaceholderconfigurer placeholderconfigurer() { return new propertysourcesplaceholderconfigurer(); }
my context definition:
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="co.com"/> <context:property-placeholder location="classpath:configurationservices.properties" /> </beans>
a simple main test:
public class mytest { public static void main(string[] args) throws exception { applicationcontext context = new classpathxmlapplicationcontext("spring/core-config.xml"); configuracion load = (configuracion) context.getbean(configuracion.class); system.out.println(load.getpropiedad("formatonombreserie")); } }
a unit test:
@contextconfiguration(classes=configuracion.class) @runwith(springjunit4classrunner.class) public class configtest { @autowired private configuracion configuration; @test public void testconfig() { assertthat(configuration.getpropiedad ("formatonombreserie"), is("1.2_3")); } }
and jax-rs service:
@path("/poc") @produces("application/json") public class rest { @autowired private configuracion configuracion; @get @path("/prop") public string devolverpropiedad() { system.out.println("propiedad: " + configuracion.getpropiedad ("formatonombreserie")); return configuracion.getpropiedad("formatonombreserie"); } }
when run main test @value work fine, junit test work fine too, when deploy war inside wildfly 10.0.0 server, jax-rs response null...
any idea?
Comments
Post a Comment