Springmvc 4.2 uses ${adminpath} cannot resolve to value in properties file

Source: Internet
Author: User


Problem Description: I want to configure AdminPath in a unified configuration, it is convenient to configure the permissions later, so I want to map to ${adminpath} after @requestmapping, but the value is not obtained here.

* *
 user Controller
 * @author thinkgem
 * @version 2013-8-29
 *
/@Controller @RequestMapping ( Value = "${adminpath}/sys/user") public
class Usercontroller extends Basecontroller {
	@Autowired
	private UserService userservice;
	@Value ("${adminpath}")
	private String password;
	@ResponseBody
	@RequiresPermissions ("Sys:user:view")
	@RequestMapping (value = {"ListData"})
	Public Page<user> listData (user user, HttpServletRequest request, httpservletresponse response, model model) {
		Page <User> page = Userservice.finduser (new page<user> (request, response), User);
		
		SYSTEM.OUT.PRINTLN ("Password as:" +password);
		return page;
	}
}

Known: @Value annotations can get the values in the properties file.

If you add a configuration <util:properties> tag, you can get the value by @value ("#{app_prop[' Jdbc.driver '}"). At this point, the value cannot still be taken from @value ("${adminpath}").

<!--load an instance of the App property, which can be referenced by a  String jdbcdriver @Value ("#{app_prop[' Jdbc.driver '}")-
    <util:properties Id= "App_prop" location= "Classpath*:test01.properties" local-override= "true"/>
I would like to take the value from the properties file by adding the following configuration through the $ character.

<!--load Configuration Properties File--
	<context:property-placeholder ignore-unresolvable= "true" location= "classpath*: Test01.properties "/>
Note: In this way, if you have the following configuration in the Spring-mvc.xml file, you must not be missing the following red section:

The function and principle analysis of use-default-filters attribute of Context:component-scan tag

<!--configuring component scans, SPRINGMVC only controller annotations--
use-default-filters= "false">
    <context: Include-filter type= "Annotation" expression= "Org.springframework.stereotype.Controller"/> </context
: Component-scan>
After I have added the Use-default-filters property, you can get the desired value through the $ symbol.

For more information, please refer to the article: Five Ways to read the properties file content in Java is no longer a challenge

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.