0

我有一个标准的 PMF 类:

public class PMF {

    private static final PersistenceManagerFactory persistenceManagerFactory = JDOHelper
        .getPersistenceManagerFactory("transactions-optional");

    private PMF() {
    }

    public static PersistenceManagerFactory get() {
        return persistenceManagerFactory;
    }

}

在本地 appengine 服务器上运行,当我第一次调用 PMF.get() 时,我得到以下异常:

javax.jdo.JDOFatalInternalException: Unexpected exception caught.
    at javax.jdo.JDOHelper.invokeGetPersistenceManagerFactoryOnImplementation(JDOHelper.java:1193)
    at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:808)
    at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:1093)
    at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:919)
    at com.myapp.framework.PMF.<clinit>(PMF.java:17)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at com.google.appengine.tools.development.agent.runtime.RuntimeHelper.checkRestricted(RuntimeHelper.java:70)
    at com.google.appengine.tools.development.agent.runtime.Runtime.checkRestricted(Runtime.java:64)
    ...
NestedThrowablesStackTrace:
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
    at javax.jdo.JDOHelper$16.run(JDOHelper.java:1965)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.jdo.JDOHelper.invoke(JDOHelper.java:1960)
    at javax.jdo.JDOHelper.invokeGetPersistenceManagerFactoryOnImplementation(JDOHelper.java:1166)
    ...
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.LogManager
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at com.google.appengine.tools.development.agent.runtime.RuntimeHelper.checkRestricted(RuntimeHelper.java:70)
    at com.google.appengine.tools.development.agent.runtime.Runtime.checkRestricted(Runtime.java:64)
    at org.apache.log4j.Logger.getLogger(Logger.java:104)
    at org.datanucleus.util.Log4JLogger.<init>(Log4JLogger.java:49)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance_(Runtime.java:127)
    at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance(Runtime.java:135)
    at org.datanucleus.util.NucleusLogger.getLoggerInstance(NucleusLogger.java:140)
    at org.datanucleus.util.NucleusLogger.<clinit>(NucleusLogger.java:106)
    at org.datanucleus.plugin.PluginRegistryFactory.newInstance(PluginRegistryFactory.java:104)
    at org.datanucleus.plugin.PluginRegistryFactory.newPluginRegistry(PluginRegistryFactory.java:63)
    at org.datanucleus.plugin.PluginManager.<init>(PluginManager.java:61)
    at org.datanucleus.plugin.PluginManager.createPluginManager(PluginManager.java:427)
    at org.datanucleus.NucleusContext.<init>(NucleusContext.java:224)
    at org.datanucleus.NucleusContext.<init>(NucleusContext.java:204)
    at org.datanucleus.NucleusContext.<init>(NucleusContext.java:182)
    at org.datanucleus.api.jdo.JDOPersistenceManagerFactory.<init>(JDOPersistenceManagerFactory.java:409)
    at org.datanucleus.api.jdo.JDOPersistenceManagerFactory.createPersistenceManagerFactory(JDOPersistenceManagerFactory.java:294)
    at org.datanucleus.api.jdo.JDOPersistenceManagerFactory.getPersistenceManagerFactory(JDOPersistenceManagerFactory.java:195)
    ... 82 more

我的日志记录设置非常标准: - WEB-INF 文件夹中的 logging.properties 并在 appengine-web.xml 中引用 - 我的 src 文件夹根目录下的 log4j.properties:

log4j.rootLogger=INFO, console

# Configure the console as our one appender
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%c] - %m%n

# tighten logging on the DataNucleus Categories
log4j.category.DataNucleus.JDO=WARN, A1
log4j.category.DataNucleus.Persistence=WARN, A1
log4j.category.DataNucleus.Cache=WARN, A1
log4j.category.DataNucleus.MetaData=WARN, A1
log4j.category.DataNucleus.General=WARN, A1
log4j.category.DataNucleus.Utility=WARN, A1
log4j.category.DataNucleus.Transaction=WARN, A1
log4j.category.DataNucleus.Datastore=WARN, A1
log4j.category.DataNucleus.ClassLoading=WARN, A1
log4j.category.DataNucleus.Plugin=WARN, A1
log4j.category.DataNucleus.ValueGeneration=WARN, A1
log4j.category.DataNucleus.Enhancer=WARN, A1
log4j.category.DataNucleus.SchemaTool=WARN, A1

我的 lib 文件夹中包含的库是: - 使用 eclipse google 插件包含的 sdk 中的所有 GAE lib - 使用 ivy 和 ivy eclipse 插件包含的 Spring MVC、Jackson 和 Aspectj:

<dependencies>
    <dependency org="org.springframework" name="spring-webmvc" rev="3.2.0.RELEASE" />
    <dependency org="org.codehaus.jackson" name="jackson-mapper-asl" rev="1.9.11" />
    <dependency org="org.aspectj" name="aspectjrt" rev="1.7.1" />
    <dependency org="org.aspectj" name="aspectjweaver" rev="1.7.1" />
</dependencies>

我真的不明白为什么它会失败,因为 GAE 通常支持 log4j。

4

1 回答 1

0

我从 spring 依赖项中排除了 log4j,我不再收到错误。在我的常春藤文件中:

<dependency org="org.springframework" name="spring-webmvc" rev="3.2.0.RELEASE">
    <exclude org="log4j" module="log4j" />
</dependency>
于 2013-02-08T09:06:06.180 回答