非法访问异常:Eclipse持久性本地化

时间:2014-03-09 13:28:57

标签: java jpa

我正在使用JPA和Spring MVC开发一个Web应用程序,我对Eclipse Persistence本地化有一个恼人的例外。这是堆栈跟踪:

mars 09, 2014 2:23:06 PM org.apache.catalina.loader.WebappClassLoader findResourceInternal
Infos: Illegal access: this web application instance has been stopped already.  Could not load org/eclipse/persistence/internal/localization/i18n/LoggingLocalizationResource_fr.properties.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
mars 09, 2014 2:23:06 PM org.apache.catalina.loader.WebappClassLoader loadClass
Infos: Illegal access: this web application instance has been stopped already.  Could not load org.eclipse.persistence.internal.localization.i18n.LoggingLocalizationResource_fr_FR.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1600)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    at java.util.ResourceBundle$Control.newBundle(ResourceBundle.java:2566)
    at java.util.ResourceBundle.loadBundle(ResourceBundle.java:1436)
    at java.util.ResourceBundle.findBundle(ResourceBundle.java:1400)
    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1296)
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:795)
    at org.eclipse.persistence.internal.localization.EclipseLinkLocalization.buildMessage(EclipseLinkLocalization.java:60)
    at org.eclipse.persistence.internal.localization.EclipseLinkLocalization.buildMessage(EclipseLinkLocalization.java:34)
    at org.eclipse.persistence.internal.localization.LoggingLocalization.buildMessage(LoggingLocalization.java:25)
    at org.eclipse.persistence.logging.AbstractSessionLog.formatMessage(AbstractSessionLog.java:987)
    at org.eclipse.persistence.logging.DefaultSessionLog.log(DefaultSessionLog.java:142)
    at org.eclipse.persistence.internal.sessions.AbstractSession.log(AbstractSession.java:3480)
    at org.eclipse.persistence.internal.sessions.AbstractSession.log(AbstractSession.java:4669)
    at org.eclipse.persistence.internal.sessions.AbstractSession.log(AbstractSession.java:4641)
    at org.eclipse.persistence.internal.sessions.AbstractSession.log(AbstractSession.java:4617)
    at org.eclipse.persistence.internal.sessions.AbstractSession.log(AbstractSession.java:4539)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.logout(DatabaseSessionImpl.java:937)
    at org.eclipse.persistence.sessions.server.ServerSession.logout(ServerSession.java:776)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.removeSessionFromGlobalSessionManager(EntityManagerSetupImpl.java:511)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.undeploy(EntityManagerSetupImpl.java:2850)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.close(EntityManagerFactoryDelegate.java:267)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.finalize(EntityManagerFactoryDelegate.java:344)
    at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
    at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:101)
    at java.lang.ref.Finalizer.access$100(Finalizer.java:32)
    at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:190)

由于我是JPA和Spring MVC的新手,我不知道导致此异常的原因。为什么我有这个例外以及如何解决它?感谢。

1 个答案:

答案 0 :(得分:0)

我已将Eclipse WTP服务器设置为“在构建事件后自动发布”。每次自动发布后,我都遇到了与您显示的相同的错误消息。

有两种方法可以解决这个问题。

  • 将Eclipse服务器设置变为“从不自动发布”。

  • 添加一个Servlet Shutdown Hook,它会明确关闭JPA的EntityManagerFactory。

您可以轻松地向ServletContextListener添加一个击落钩子。在我的例子中,这是一个GuiceServletContextListener,但它应该对任何ServletContextListener都有效。

import javax.persistence.EntityManagerFactory;
import javax.servlet.ServletContextEvent;
import javax.servlet.annotation.WebListener;

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.servlet.GuiceServletContextListener;

@WebListener
public class BmjServletContextListener extends GuiceServletContextListener {

    Injector injector;

    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        injector.getInstance(EntityManagerFactory.class).close(); // <--- POI !!
        super.contextDestroyed(servletContextEvent);
    }

    public void contextInitialized(ServletContextEvent servletContextEvent) {
        super.contextInitialized(servletContextEvent);
    }

    protected Injector getInjector() {
        injector = Guice.createInjector(new MyModule1(), new MyModule2());
        return injector;
    }
}