加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

java-Spring MVC 3 getInitParameter

发布时间:2020-12-15 01:19:27 所属栏目:大数据 来源:网络整理
导读:当我以前没有使用Spring开发servlet应用程序时,我可以在servlet中读取如下配置参数: @Override public void init() throws ServletException { ServletContext sc = getServletContext(); String someSetting = sc.getInitParameter("someSetting");} 但是,

当我以前没有使用Spring开发servlet应用程序时,我可以在servlet中读取如下配置参数:

@Override public void init() throws ServletException { 

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

}

但是,我现在正在使用Spring MVC开发应用程序,这意味着我自己不再拥有servlet,而是使用Spring的DispatcherServlet.

现在,我如何访问spring-servlet.xml中的那些初始化参数以将它们传递给我的一个bean?

我正在使用Spring 3,并且它是n00b.每当我看到一个没有id的bean时,我的脑袋就会翻转XD

最佳答案
我猜您可以在控制器中@Inject ServletContext,然后从那里获取参数.

更好的是,将@Value与specificPropertyPlaceholderConfigurer一起使用. See this answer

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读