ola pessoal, estou com um probleminha num exemplo de um livro q estou estudando…fiz um teste unitario e está me retornando o seguinte erro:
[b]
Testcase: gravar(facade.UsuarioFacadeTest): Caused an ERROR
org/apache/commons/logging/LogFactory
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.context.support.AbstractApplicationContext.(AbstractApplicationContext.java:146)
at org.springframework.context.support.AbstractRefreshableApplicationContext.(AbstractRefreshableApplicationContext.java:84)
at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.(AbstractRefreshableConfigApplicationContext.java:59)
at org.springframework.context.support.AbstractXmlApplicationContext.(AbstractXmlApplicationContext.java:58)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:136)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
at facade.UsuarioFacadeTest.gravar(UsuarioFacadeTest.java:50)
[/b]
sou iniciante em java e spring…nao sei se o problema é no applicationContext…segue o tal:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework/schema/aop"
xmlns:tx="http://www.springframework/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!-- Configurador que substitui os marcadores ${...} com os valores definidos no arquivo de properties -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:/jdbc.properties"/>
</bean>
<!-- Local C3PO DataSource que Trabalha em qualquer ambiente, em ambientes de produção use jndi -->
<bean id="dataSource" class="com.mchange.v2.c3po.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!--JPA EntityManagerFactory -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="generateDd1" value="false" />
<property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect"/>
</bean>
</property>
</bean>
<!--Transaction Manager para um JPS EntityManagerFactory simples(alternativa ao JTA) -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<!--Instrui o Spring a realizar gerenciamento transacional declarativo automático nas classes anotadas -->
<tx:annotation-driven/>
<!--PostProcessors para realizar injecao de recursos de acordo com a especificação jpa (@PersistenceContext, @PersistenceUnit) -->
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<!--PostProcessors para realizar a conversao de exceçoes nas classes @Repository (das exceções nativas como jpa
PersistenceExceptions to Sprong's DataAccessException ) -->
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<!--Será automaticamente transacional graças ao @Transactional.
EntityManager irá ser auto-injetado graças ao @PersistenceContext.
PersistenceException será automaticamente convertido graças ao @Repository.-->
<bean id="usuario" class="dominio.Usuario" scope="session" />
<bean id="usuarioDao" class="dao.UsuarioDao" />
<bean id="usuarioFacade" class="facade.UsuarioFacade">
<property name="usuarioDao" ref="usuarioDao"/>
</bean>
<bean id="contato" class="dominio.Contato" scope="session" />
<bean id="contatoDao" class="dao.ContatoDao" />
<bean id="contatoFacade" class="facade.ContatoFacade">
<property name="contatoDao" ref="contatoDao"/>
</bean>
<bean id="endereco" class="dominio.Endereco" scope="session" />
<bean id="enderecoDao" class="dao.EnderecoDao" />
<bean id="enderecoFacade" class="facade.EnderecoFacade">
<property name="enderecoDao" ref="enderecoDao"/>
</bean>
<bean id="meioContato" class="dominio.MeioContato" scope="session" />
<bean id="meioContatoDao" class="dao.MeioContatoDao" />
<bean id="meioContatoFacade" class="facade.MeioContatoFacade">
<property name="meioContatoDao" ref="meioContatoDao"/>
</bean>
</beans>
aqui segue o metodo:
@Test
public void gravar() {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
Usuario usuarioTeste = new Usuario();
usuarioTeste.setLogin("guest");
usuarioTeste.setNome("guest");
usuarioTeste.setSenha("guest");
System.out.println("gravar usuário");
UsuarioFacade instance = (UsuarioFacade) context.getBean("usuarioFacade");
Usuario result = instance.gravar(usuarioTeste);
try{
assertNotNull(result.getIdUsuario());
}catch(AssertionError e){
fail("Falhou a gravação de usuário.");
}
}
conto com vcs colegas, muito obrigado, abraços.