当我运行我的spring junit测试时,我收到此错误消息:
Caused by:
java.lang.NoSuchMethodError: org/slf4j/impl/StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder;
...
java.lang.ClassFormatError: JVMCFRE074 no Code attribute specified; class=javax/persistence/PersistenceException, method=<init>()V, pc=0
你能帮我找一下这个错误信息的原因吗?似乎我对slf4j的依赖有一些问题 - 但我在项目中有它们。
测试类:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"/businessApplicationContextTest.xml"})
@TransactionConfiguration(transactionManager="transactionManager", defaultRollback=true)
@Transactional
public class LogicHandlerTest {
@SessionFactory
SessionFactory sessionFactory;
@Before
public void setup() {System.out.println("@Before");}
@Test
public void testDummy() {
System.out.println("testDummy");
assert(true);
}
}
Spring测试上下文配置:
<!-- DATASOURCE -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
<property name="url" value="jdbc:hsqldb:mem:test"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
<!-- SESSION FACTORY -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.test.dummyproject.entity"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.jdbc.batch_size">100</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.connection.autocommit">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
</props>
</property>
</bean>
<!-- TRANSACTION MANAGER -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
DEPENDENCIES(来自POM.XML的版本):
hibernate 3.2.3.ga
hibernate-annotations 3.3.1.GA
hibernate-commons-annotations 3.2.0.Final
javaee-api 6.0
slf4j-api 1.6.4
slf4j-log4j12 1.6.4
答案 0 :(得分:0)
您似乎没有在Test中注入SessionFactory,
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" auto-wire="byName">
@Resource
SessionFactory sessionFactory
更新:在类路径中添加这些jar
01.antlr-2.7.6
02.commons-collections-3.1
03.dom4j-1.6.1
04.hibernate3
05.database specific jar
06.javassist-3.4.GA
07.jta-1.1
08.slf4j-api-1.5.6
09.slf4j-simple-1.5.6
答案 1 :(得分:0)
该错误消息的原因是maven依赖项中的混乱 - 我从我的项目中删除了javaee 6依赖项,现在一切正常。 (因为websphere服务器已经包含javaee 6库)。