gpt4 book ai didi

java - 缺少资源异常 : Can't find bundle for base name

转载 作者:行者123 更新时间:2023-12-01 10:32:52 25 4
gpt4 key购买 nike

我知道在 stackoverflow 和其他论坛上有很多关于此错误的问题和答案。但我仍然找不到解决方案...

我的代码:

package com.sodifrance.apex.presentation.generic.utils;

import java.util.ResourceBundle;

public class EnumTranslator {

private static EnumTranslator instance = null;

private EnumTranslator() {
}

public static EnumTranslator getDefaut() {
if (instance == null)
{
instance = new EnumTranslator();
}
return instance;
}

public String translate(Enum<?> enumerationValue) {
String localizedMessage = "";

if (enumerationValue != null)
{
ResourceBundle b = ResourceBundle.getBundle("resources.enumerations");

localizedMessage = enumerationValue.name();

if (b != null)
{
localizedMessage = b.getString(enumerationValue.getDeclaringClass().getName() + "." + enumerationValue.name());
}
}

return localizedMessage;
}
}

Tomcat 控制台:

java.util.MissingResourceException: Can't find bundle for base name resources.enumerations, locale fr_FR at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1564) at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1387) at java.util.ResourceBundle.getBundle(ResourceBundle.java:773) at com.presentation.generic.utils.EnumTranslator.translate(EnumTranslator.java:25) at com.presentation.entry.societe.EntryChoixTypeSocieteAction.execute(EntryChoixTypeSocieteAction.java:53) at com.presentation.generic.back.BackRequestProcessor.processActionPerform(BackRequestProcessor.java:118) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228) at com.presentation.generic.back.BackRequestProcessor.process(BackRequestProcessor.java:63) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913) at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449) at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.presentation.generic.security.EncodingFilter.doFilter(EncodingFilter.java:121) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.presentation.generic.security.ApplicationFilter.doFilter(ApplicationFilter.java:72) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)

当我在 Debug模式下检查这一行时:

ResourceBundle b = ResourceBundle.getBundle("resources.enumerations");

我有这样的消息:

The method getBundle(String) is undefined for the type Enum Translator

我的文件配置: enter image description here

最佳答案

Resource.getBundle 采用 FQCN 作为参数。在语句 ResourceBundle.getBundle("resources.enumerations") 中,JRE 正在查找文件 resources/enumerations<_local>.properties

在您的示例中,您应该使用 getBundle("com.sod.ap.properties.enumerations")

关于java - 缺少资源异常 : Can't find bundle for base name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35000232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com