How to get properties in JSP files using spring mvc 3

前端 未结 3 1204
庸人自扰
庸人自扰 2021-02-04 08:49

I am very new to spring mvc 3 annotation based application. I have two properties files - WEB-INF\\resources\\general.properties, WEB-INF\\resources\\jdbc_config.properties

3条回答
  •  广开言路
    2021-02-04 09:25

    I ended up using Environment

    Add these lines to config

    @PropertySource("classpath:/configs/env.properties")
    public class WebConfig extends WebMvcConfigurerAdapter{...}
    

    You can get the properties from controller using autowired Environment

    public class BaseController {
        protected final Logger LOG = LoggerFactory.getLogger(this.getClass());
    
        @Autowired
        public Environment env;
    
        @RequestMapping("/")
        public String rootPage(ModelAndView modelAndView, HttpServletRequest request, HttpServletResponse response) {
            LOG.debug(env.getProperty("download.path"));
            return "main";
        }
    }
    

提交回复
热议问题