@Value annotation

There are two xml configuration files in SpringMVC:

1. applicationContext.xml, this is the main configuration file of Spring, including the configuration information of the bean definition or scanning, data source, transaction, etc. of the service layer of the dao layer.

2. xxx-servlet.xml, this is the mvc configuration file, including bean definition or scanning of the controller layer, static resource access and view configuration

The information in the properties configuration file is defined in applicationContext.xml, so it can be accessed using the @Value annotation at the service layer, but cannot be accessed using the @Value annotation at the Controller layer.

If you want to use @Value to access the properties configuration in the Controller layer, you need to define the properties configuration file in xxx-servlet.xml as well.

	<!-- Load properties file -->
	<context:property-placeholder location="classpath:resource/resource.properties"/>

config file:

IMAGE_SERVER_URL=http://111.231.73.14/

The control layer uses: '

	@Value("${IMAGE_SERVER_URL}")
	private String IMAGE_SERVER_URL;
Reproduced in: SpringMVC obtains properties configuration through annotation @Value


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324782216&siteId=291194637