开发者

Spring MVC 3 getInitParameter

开发者 https://www.devze.com 2023-03-01 15:49 出处:网络
When I previously developed servlet applications without Spring, I could read configuration parameters like this in my servlet:

When I previously developed servlet applications without Spring, I could read configuration parameters like this in my servlet:

@Override public void init() throws ServletException { 

    ServletContext sc = getServletContext();
    String someSetting = sc.getInitParameter("someSetting");

}

However, I'm developing an application wi开发者_运维百科th Spring MVC now, which means I no longer have a servlet myself, but use Spring's DispatcherServlet.

Now, how can I access those init parameters in spring-servlet.xml to pass them to one of my beans?

I'm using Spring 3, and am a n00b with it. Every time I see a bean without an id, my mind flips XD


I guess you can @Inject a ServletContext in your controllers, and take the params from there.

Of better, use @Value together with a specificPropertyPlaceholderConfigurer. See this answer


Do you really need these to be init-parameters in the Servlet context?

In Spring you can just inject values into your beans from a properties file using PropertyPlaceholderConfigurer.

0

精彩评论

暂无评论...
验证码 换一张
取 消