spring - @Value autowire problems -


i trying understand why autowired @value("${delimiter}") property not working. framework finds .properties file not map delimiter property.

tested.java

public class tested{      @value("${delimiter}")     protected string delimiter;  } 

tester.java

@runwith( springjunit4classrunner.class )
@contextconfiguration(locations = {"/tester-context.xml"} )

public class tester{

 @value("${delimiter}")     protected string delimiter;   @test      public void test() {                fail("not yet implemented");      }   

}

src/test/resources/tester-context.xml

<?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:beans="http://www.springframework.org/schema/beans"         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:property-placeholder location="classpath*:test.properties" />  </beans> 

web-inf/classes/test.properties

delimiter = |||  

exception message snippet

caused by: org.springframework.beans.factory.beancreationexception: not autowire field: private java.lang.string com.tester.delimiter; nested exception java.lang.illegalargumentexception: not resolve placeholder 'delimiter' in string value "${delimiter}"     @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject(autowiredannotationbeanpostprocessor.java:561)     @ org.springframework.beans.factory.annotation.injectionmetadata.inject(injectionmetadata.java:88)     @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocesspropertyvalues(autowiredannotationbeanpostprocessor.java:331)     ... 28 more caused by: java.lang.illegalargumentexception: not resolve placeholder 'delimiter' in string value "${delimiter}" ... 

with maven resources being used tests 1 placed in resources folder, typically src\test\resources

in case move test.properties file src\test\resources folder.

this answer similar question shows default maven behavior.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -