0

I'm stucked with this problem for hours. Hope someone can save me up. Here is my configuration:

<context:annotation-config />
<context:component-scan base-package="com.emory.athena" />
<bean id="appProperty" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <array>
            <value>classpath:Athena.properties</value>
        </array>
    </property>
</bean>

Here is my usage:

@Service
public class ExcelDownloadService {

    @Value("${chromeDriverLocation}")
    private String driverLocation;

Here is the property file:

chromeDriverLocation = my_value

I put the property file into a resource folder marked with resource type in IntelliJ, and this can be reached in the XML configuration(IDE shows this and file is in the class fold after building). Meanwhile there is no error when init this bean. But I can't read the right value in my var, it is always NULL. Can anybody tell me what's wrong with this config, and how can I solve this? Will be very grateful!

Add project structure screenshot: structure

Update: Seems this problem is caused by inproperate inject order. I read this injected value in the constructor like this:

public ExcelDownloadService() {
    System.setProperty("webdriver.chrome.driver", driverLocation);
}

If i move this var reading to my other methods, all the config values are read correctly. Now the problem is, when @Value really injects the value to my val?

Emory
  • 1
  • 2

0 Answers0