编辑3:它正在工作!长话短说:在glassfish lib文件夹中有:slf4j-api-1.5.8.jar和jlf4j-jdk14-1.5.8.jar!无论如何我把它们移到了在lib下创建的“旧”文件夹中,然后将以下内容复制到文件夹中:
SLF4J-API-1.6.1.jar
SLF4J-log4j12-1.6.1.jar
JCL-过SLF4J-1.6.1.jar
log4j的-1.2.16.jar
(正如我在类路径中所拥有的那样,但现在到了应用程序服务器,一切都按预期工作)
我也可以将log4j.xml文件放入glassfish中,但我只是将它留给我的应用程序,这样我就可以进行特定于应用程序的日志记录.
我将提供一个答案,重新修改问题,使其更有用(目前过多的信息没有用).
更新:我会自我回答,但已经等了很久.接受史蒂文斯回答,因为这是最有帮助的,同时搞清楚这一点.
以下是历史……
编辑2:我不知道为什么,但它可能与glafish v3上部署有关. Glassfish使用Java实用日志,这是一张图片http://blog.saddey.net/2010/03/27/how-to-deploy-a-grails-application-to-glassfish/,描述了一些Grails人员为了使日志工作所做的事情(不是我使用grails),也许使用jul更有意义,如图所示?
如果我在不删除app frist的情况下重新部署,我也会收到这些错误:
SEVERE: log4j:ERROR log4j called after unloading,see http://logging.apache.org/log4j/1.2/faq.html#unload.
SEVERE: java.lang.IllegalStateException: Class invariant violation
编辑,我仍然卡住了:
Logging适用于Spring和Struts2,但我无法使用log4j打印出sql(或其他任何东西),这很重要因为虽然我可以使用< property name =“hibernate.show_sql来使用hibernate来打印SQL “value =”true“/>在persistence.xml中,显示sql参数的唯一方法是通过日志记录,这对我来说至关重要.
为了更加清楚,当应用程序启动时会有一些与hibernate相关的信息消息,但是当我查询数据库时,没有显示任何内容.
因为我疯了,我会列出我的pom,log4j.xml,applicationContext.xml,如果我有时间,我会提供链接到我访问过的很多网站(包括SO Q& A).
的pom.xml
一个显而易见的问题是伐木罐到底是什么,答案是:
jcl-over-slf4j-1.6.1.jar,slf4j-log4j12-1.6.1.jar,log4j-1.2.16.jar和slf4j-api-1.6.1(我也排除了commons-logging)…也试了版本1.5.8 for jcl-over-slf4j,slf4j-api.
MysqLMysqL-connector-java
的log4j.xml
sql statements (same as show_sql=true) -->
sql">
applicationContext.xml(trimmed)
MysqLDataSource" />
factorybean">
启动时打印到控制台的内容:
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: Hibernate Annotations 3.5.0-Final
INFO: Hibernate 3.5.0-Final
INFO: hibernate.properties not found
INFO: Bytecode provider name : javassist
INFO: using JDK 1.4 java.sql.Timestamp handling
INFO: Hibernate Commons Annotations 3.2.0.Final
INFO: Hibernate EntityManager 3.5.0-Final
...removed logging for peristence unit which was mostly just pages of "Binding Named query:..."
INFO: Hibernate Validator not found: ignoring
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
INFO: Using provided datasource
INFO: RDBMS: DB2 UDB for AS/400,version: 06.01.0000 V6R1m0
INFO: JDBC driver: AS/400 ToolBox for Java JDBC Driver,version: 9.4
INFO: Using dialect: org.hibernate.dialect.DB2400Dialect
INFO: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
INFO: Transaction strategy: org.hibernate.ejb.transaction.JoinableCMTTransactionFactory
INFO: instantiating TransactionManagerLookup: org.hibernate.transaction.SunONETransactionManagerLookup
INFO: instantiated TransactionManagerLookup
INFO: Automatic flush during beforeCompletion(): disabled
INFO: Automatic session close at end of transaction: disabled
INFO: Scrollable result sets: enabled
INFO: JDBC3 getGeneratedKeys(): enabled
INFO: Connection release mode: auto
INFO: Default batch fetch size: 1
INFO: Generate sql with comments: disabled
INFO: Order sql updates by primary key: disabled
INFO: Order sql inserts for batching: disabled
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
INFO: Using ASTQueryTranslatorFactory
INFO: Query language substitutions: {}
INFO: JPA-QL strict compliance: enabled
INFO: Second-level cache: enabled
INFO: Query cache: disabled
INFO: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
INFO: Optimize cache for minimal puts: disabled
INFO: Structured second-level cache entries: disabled
INFO: Statistics: disabled
INFO: Deleted entity synthetic identifier rollback: disabled
INFO: Default entity-mode: pojo
INFO: Named query checking : enabled
INFO: Check Nullability in Core (should be disabled when Bean Validation is on): disabled
INFO: building session factory
INFO: Not binding factory to JNDI,no JNDI name configured
INFO: JNDI InitialContext properties:{}
INFO: PWC1412: WebModule[null] ServletContext.log():Initializing Spring root WebApplicationContext
INFO: Root WebApplicationContext: initialization started
INFO: Refreshing Root WebApplicationContext: startup date [Wed Jul 27 15:04:50 MDT 2011]; root of context hierarchy
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
INFO: JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
INFO: JSR-330 'javax.inject.Named' annotation found and supported for component scanning
INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO: Building JPA container EntityManagerFactory for persistence unit 'co05in'
...removed logging for peristence unit which was mostly just pages of "Binding Named query:..."
INFO: Hibernate Validator not found: ignoring
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
INFO: Using provided datasource
INFO: RDBMS: DB2 UDB for AS/400,no JNDI name configured
INFO: JNDI InitialContext properties:{}
INFO: Bean 'entityManagerFactory' of type [class org.springframework.orm.jpa.LocalContainerEntityManagerfactorybean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListablebeanfactory@5ecada2f: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalrequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,dataSource,org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0,entityManagerFactory,transactionManager,inventoryService,codeService,orderService,addressService,partService,pickTicketService,employeeService,batchService,rateCodeService,payPeriodService,basicORMParser,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor]; root of factory hierarchy
INFO: Using JTA UserTransaction: com.sun.enterprise.transaction.UserTransactionImpl@72ae2192
INFO: Using JTA TransactionManager: com.sun.enterprise.transaction.TransactionManagerHelper@61e3310
INFO: Using JTA TransactionSynchronizationRegistry: com.sun.enterprise.transaction.TransactionSynchronizationRegistryImpl@2877770c
INFO: Root WebApplicationContext: initialization completed in 4725 ms
INFO: Parsing configuration file [struts-default.xml]
INFO: Parsing configuration file [struts-plugin.xml]
INFO: Parsing configuration file [struts.xml]
INFO: Initializing Struts-Spring integration...
INFO: Setting autowire strategy to name
INFO: ... initialized Struts-Spring integration successfully
INFO: WEB0671: Loading application [com.aerose_PartGroupMaster_war_2011.04.12] at [/com.aerose_PartGroupMaster_war_2011.04.12]
INFO: com.aerose_PartGroupMaster_war_2011.04.12 was successfully deployed in 25,884 milliseconds.
INFO: log4j: reset attribute= "false".
INFO: log4j: Threshold ="null".
INFO: log4j: Retreiving an instance of org.apache.log4j.Logger.
INFO: log4j: Setting [com.opensymphony] additivity to [true].
INFO: log4j: Level value for com.opensymphony is [ERROR].
INFO: log4j: com.opensymphony level set to ERROR
INFO: log4j: Class name: [org.apache.log4j.ConsoleAppender]
INFO: log4j: Setting property [target] to [System.out].
INFO: log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
INFO: log4j: Setting property [conversionPattern] to [%d{ABSOLUTE} %5p %c{1}:%L - %m%n].
INFO: log4j: Adding appender named [STDOUT] to category [com.opensymphony].
INFO: log4j: Retreiving an instance of org.apache.log4j.Logger.
INFO: log4j: Setting [org.apache.struts2] additivity to [true].
INFO: log4j: Level value for org.apache.struts2 is [ERROR].
INFO: log4j: org.apache.struts2 level set to ERROR
INFO: log4j: Adding appender named [STDOUT] to category [org.apache.struts2].
INFO: log4j: Retreiving an instance of org.apache.log4j.Logger.
INFO: log4j: Setting [org.hibernate] additivity to [true].
INFO: log4j: Level value for org.hibernate is [TRACE].
INFO: log4j: org.hibernate level set to TRACE
INFO: log4j: Adding appender named [STDOUT] to category [org.hibernate].
INFO: log4j: Retreiving an instance of org.apache.log4j.Logger.
INFO: log4j: Setting [org.hibernate.hql] additivity to [true].
INFO: log4j: Level value for org.hibernate.hql is [TRACE].
INFO: log4j: org.hibernate.hql level set to TRACE
INFO: log4j: Adding appender named [STDOUT] to category [org.hibernate.hql].
INFO: log4j: Retreiving an instance of org.apache.log4j.Logger.
INFO: log4j: Setting [org.hibernate.sql] additivity to [true].
INFO: log4j: Level value for org.hibernate.sql is [TRACE].
INFO: log4j: org.hibernate.sql level set to TRACE
INFO: log4j: Adding appender named [STDOUT] to category [org.hibernate.sql].
INFO: log4j: Retreiving an instance of org.apache.log4j.Logger.
INFO: log4j: Setting [org.hibernate.type] additivity to [true].
INFO: log4j: Level value for org.hibernate.type is [TRACE].
INFO: log4j: org.hibernate.type level set to TRACE
INFO: log4j: Adding appender named [STDOUT] to category [org.hibernate.type].
INFO: log4j: Retreiving an instance of org.apache.log4j.Logger.
INFO: log4j: Setting [org.springframework] additivity to [true].
INFO: log4j: Level value for org.springframework is [WARN].
INFO: log4j: org.springframework level set to WARN
INFO: log4j: Adding appender named [STDOUT] to category [org.springframework].
INFO: log4j: Level value for root is [INFO].
INFO: log4j: root level set to INFO
INFO: log4j: Adding appender named [STDOUT] to category [root].