我有一个标准的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谷歌插件包含来自sdk的所有GAE lib - Spring MVC,Jackson和Aspectj包括使用常春藤和常春藤eclipse插件:
<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。
答案 0 :(得分:0)
我从spring依赖项中排除了log4j,我不再收到错误。 在我的常春藤文件中:
<dependency org="org.springframework" name="spring-webmvc" rev="3.2.0.RELEASE">
<exclude org="log4j" module="log4j" />
</dependency>