找不到resource bundle与配置load-on-startup

在开发Struts应用时遇到找不到resource bundle的问题,即使资源放在正确位置也无法解决。通过在web.xml的action配置中添加<load-on-startup>1</load-on-startup>,问题得到解决。这表明resource需要在应用启动时由服务器加载到内存,而<load-on-startup>元素用于指定加载的优先级,确保资源在应用部署时初始化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

       刚接触struts,按照书上的例子写了一个web应用,但是启动了tomcat服务器后却发现总是出现找不到resource

bundle的错误。经过反复核查,也修改了不少东西,包括一点马虎以及注意resource在包中的存放位置(在/WEB-

INF/classes下),但最终仍然无法解决这个问题,实在令人挠头。后来绝望时在web.xml配置文件中在配置action

时在<init-param>后面添加了<load-on-startup>1<load-on-startup>,问题竟然解决了!

      个人理解是resource要在WEB应用启动时由WEB服务器加载(读取配置文件)到内存中,并将它们放在config

包中相关JavaBean类的实例中(<message-resoureces>和MessageResourcesConfig类相对应),但是由于没

有设置加载的优先级,导致了resource并没有被预先加载,因而出现了上述错误,因此,ActionServlet应该在启动

WEB应用前进行加载。

      后来在servlet-2_4-spec中查到了关于<load-on-startup>的说明:

     “The load-on-startup element indicates that this servlet should be loaded (instantiated and have its init() called) on the startup of the web application. The optional contents of these element must be an integer indicating the order in which the servlet should be loaded. If the value is a negative integer, or the element is not present, the container is free to load the servlet whenever it chooses. If the value is a positive 128 integer or 0, the container must load and initialize the servlet as the application is deployed”

      <load-on-startup>的内容是一个整数,代表了被加载时的优先级别。如果这个整数是负数,那么servlet容器可

以随时加载这个servlet而不受任何限制。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值