我的faces-config.xml喜欢以下。
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-
facesconfig_2_0.xsd"
version="2.0">
<application>
<message-bundle>resources.application</message-bundle>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
</application>
</faces-config>
Xhtml文件
<f:loadBundle basename="resources.application" var="msg"/>
我收到以下异常
javax.faces.view.facelets.TagAttributeException: //D:/12c_Workspace/VNPO/WebContent/login.xhtml @9,59 <f:loadBundle basename="resources.application"> Can't find bundle for base name resources.application, locale en
at com.sun.faces.facelets.tag.jsf.core.LoadBundleHandler.apply(LoadBundleHandler.java:233)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86)
at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:152)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:774)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:242)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:216)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:132)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:338)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:74)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:74)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3288)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3254)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2163)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2089)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2074)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1513)
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
Caused by: java.util.MissingResourceException: Can't find bundle for base name resources.application, locale en
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1427)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1250)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:952)
at com.sun.faces.facelets.tag.jsf.core.LoadBundleHandler.apply(LoadBundleHandler.java:227)
这是如何引起的?如何解决?
答案 0 :(得分:9)
异常清楚地表明您在运行时类路径中的application_en.properties
包中没有application.properties
或至少resources
个文件。
真的是这样。只要确保你有一个。
无关,我只是想警告<message-bundle>
和<f:loadBundle>
是互斥的。要了解差异,请前往Internationalization in JSF, when to use message-bundle and resource-bundle?
答案 1 :(得分:2)
你需要两件事:
messages.properties
文件放在班级路径中。最安全的选择是将其置于src/main/java/your/package/name
faces-config.xml
:http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd” 版本= “2.2” &GT;
<application>
<resource-bundle>
<base-name>your.package.name.messages</base-name>
<var>i18n</var>
</resource-bundle>
</application>
</faces-config>
请注意,.properties
faces-config.xml
后缀
答案 2 :(得分:1)
如果您使用的是Maven,则必须将属性文件放在src / main / resources文件夹中,而不是使用thar在src / main / java中的软件包
答案 3 :(得分:0)
以下是您可以做的事情:
第一步:保持Maven文件的安装和使用。
第二步:您需要在环境变量中设置Maven的类路径
第三步:在到达Maven目录中的mvn install
目录后,在命令提示符上使用命令/bin
安装Maven。
现在清理项目并部署Maven项目以运行。
答案 4 :(得分:-1)
使用Eclipse和Windows:您必须复制2个文件
xxxPROJECTxxx.properties
log4j.properties
这里: C:\ Eclipse的\ CONTENER \ TOMCAT \ Apache的Tomcat的7 \ lib中