VRaptor + JdbcDaoSupport - Alguém tem alguma luz (PF)

4 respostas
marcelomello

Olá pessoal,

Seguinte preciso entregar um “projeto” amanhã, e pretendo utilizar o jdbcdaosupport por questões de banco.
(tá complicado mapear as tabelas, e os selects irão utilizar muitas funcoes do oracle).

Se alguém puder dar uma mão, fico muito agradecido na questão configuração VRaptor + Spring JDBC e
um acesso ao DAO q retorne uma string somente.

Com certeza devo estar fazendo muita KÁÁÁKA…
Obs.: não foi por falta de busca no google.

Minhas configurações estão assim:

WEB-INF/applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
	
	<bean id="dataSource"
		class="org.springframework.jdbc.datasource.DriverManagerDataSource"
		>
		<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
		<property name="url" value="jdbc:oracle:thin:@1.1.1.1:dbor" />
		<property name="username" value="bla" />
		<property name="password" value="bla" />

	</bean>


	<bean id="indexDAOImpl" class="br.com.bla.vraptorspringjdbc.dao.impl.IndexDAOImpl">  
		<property name="dataSource" ref="dataSource" />  
	</bean> 

</beans>

web.xml

<context-param>
		<param-name>br.com.caelum.vraptor.packages</param-name>
		<param-value>br.com.bla.vraptorspringjdbc</param-value>
	</context-param>

	<context-param>
		<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
		<param-value>messages</param-value>
	</context-param>
    
    <listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	
	<filter>
		<filter-name>vraptor</filter-name>
		<filter-class>br.com.caelum.vraptor.VRaptor</filter-class>
	</filter>

	<filter-mapping>
		<filter-name>vraptor</filter-name>
		<url-pattern>/*</url-pattern>
		<dispatcher>FORWARD</dispatcher>
		<dispatcher>REQUEST</dispatcher>
	</filter-mapping>

IndexController

@Resource
public class IndexController {

	public final Result result;
	private IndexService service;

	/**
	 * @param result
	 */
	public IndexController(Result result, IndexService service) {
		this.result = result;
		this.service = service;
	}
	
	@Path("/")
	public void index(){
		
		String nome = service.getCodeEstacao(100);
		result.include("nomeEstacao", nome);
		
	}
	
}

IndexServiceImpl

@Component
public class IndexServiceImpl implements IndexService {

	private IndexDAO dao;
	
	
	/**
	 * @param dao
	 */
	public IndexServiceImpl(IndexDAO dao) {
		this.dao = dao;
	}

	@Override
	public String getCodeEstacao(Integer idEstacao) {
		
		String name = dao.getNameEstacaoById(idEstacao);
		return name;
	}

}

IndexDAOImpl

@Component
public class IndexDAOImpl extends JdbcDaoSupport implements IndexDAO{

	private static final String FIND_BY_PK_SQL = "Select Select ea.nm_estac_agromet " +
												 " From sam.estac_agromet ea" +
												 " Where ea.cd_estac_agromet = ? ";
	
	public JdbcTemplate template;

	public IndexDAOImpl() { }

	
	/**
	 * 
	 */
	public IndexDAOImpl(JdbcTemplate template) {
		this.template = template;
	}



	@Override
	public String getNameEstacaoById(Integer pk) {
		
		RowMapper<Estacao> callback = new EstacaoRowMapper();
		Estacao estacao = (Estacao) template.queryForObject(FIND_BY_PK_SQL, new Object[]{pk}, callback);
		
		return estacao.getNmEstacAgromet();
	}
}

Bean / Model (nao sei como vcs chamam)

public class Estacao implements Serializable {

	private static final long serialVersionUID = 3484490398399512386L;

	private Integer cdEstacAgromet;
	private String nmEstacAgromet;

	//Getters & Setters ....
}

RowMapper

public class EstacaoRowMapper implements RowMapper<Estacao> {

	@Override
	public Estacao mapRow(ResultSet rs, int rowNum)
			throws SQLException {
		
		Estacao estacao = new Estacao();
		estacao.setCdEstacAgromet(rs.getInt("cd_estac_agromet"));
		estacao.setNmEstacAgromet(rs.getString("nm_estac_agromet"));
		
		return estacao;
	}
}

Desta forma está ocorrendo o seguinte erro.

26/04/2012 15:44:37 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet default threw exception
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'indexController': Unsatisfied dependency expressed through constructor argument with index 1 of type [br.com.tecnopolis.vraptorspringjdbc.service.IndexService]: : Error creating bean with name 'indexServiceImpl': Unsatisfied dependency expressed through constructor argument with index 0 of type [br.com.tecnopolis.vraptorspringjdbc.dao.IndexDAO]: : Error creating bean with name 'indexDAOImpl': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'indexDAOImpl': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'indexServiceImpl': Unsatisfied dependency expressed through constructor argument with index 0 of type [br.com.tecnopolis.vraptorspringjdbc.dao.IndexDAO]: : Error creating bean with name 'indexDAOImpl': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'indexDAOImpl': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:730)
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:196)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1035)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:939)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:332)
	at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:43)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:328)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:265)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1101)
	at br.com.caelum.vraptor.ioc.spring.SpringBasedContainer.instanceFor(SpringBasedContainer.java:86)
	at br.com.caelum.vraptor.interceptor.InstantiateInterceptor.intercept(InstantiateInterceptor.java:46)
	at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
	at br.com.caelum.vraptor.interceptor.ExceptionHandlerInterceptor.intercept(ExceptionHandlerInterceptor.java:71)
	at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
	at br.com.caelum.vraptor.core.LazyInterceptorHandler.execute(LazyInterceptorHandler.java:61)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
	at br.com.caelum.vraptor.interceptor.ResourceLookupInterceptor.intercept(ResourceLookupInterceptor.java:69)
	at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
	at br.com.caelum.vraptor.core.EnhancedRequestExecution.execute(EnhancedRequestExecution.java:44)
	at br.com.caelum.vraptor.VRaptor$1.insideRequest(VRaptor.java:91)
	at br.com.caelum.vraptor.ioc.spring.SpringProvider.provideForRequest(SpringProvider.java:58)
	at br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:88)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'indexServiceImpl': Unsatisfied dependency expressed through constructor argument with index 0 of type [br.com.tecnopolis.vraptorspringjdbc.dao.IndexDAO]: : Error creating bean with name 'indexDAOImpl': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'indexDAOImpl': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:730)
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:196)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1035)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:939)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:332)
	at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:43)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:328)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:848)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)
	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795)
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723)
	... 39 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'indexDAOImpl': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:332)
	at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:43)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:328)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:848)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)
	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795)
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723)
	... 53 more
Caused by: java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required
	at org.springframework.jdbc.core.support.JdbcDaoSupport.checkDaoConfig(JdbcDaoSupport.java:112)
	at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
	... 64 more

Não entendo o porque está pedindo o dataSource ou o JdbcTemplate, já que nas linhas abaixo ao meu ver está sendo injetado o dataSource

INFO: Starting Servlet Engine: Apache Tomcat/6.0.26
26/04/2012 15:44:33 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
15:44:33,667  INFO [ContextLoader       ] Root WebApplicationContext: initialization started
15:44:33,821 DEBUG [StandardServletEnvironment] Initializing new StandardServletEnvironment
15:44:33,821 DEBUG [StandardServletEnvironment] Initializing new StandardServletEnvironment
15:44:33,823 DEBUG [StandardServletEnvironment] Adding [servletConfigInitParams] PropertySource with lowest search precedence
15:44:33,823 DEBUG [StandardServletEnvironment] Adding [servletConfigInitParams] PropertySource with lowest search precedence
15:44:33,823 DEBUG [StandardServletEnvironment] Adding [servletContextInitParams] PropertySource with lowest search precedence
15:44:33,823 DEBUG [StandardServletEnvironment] Adding [servletContextInitParams] PropertySource with lowest search precedence
15:44:33,832 DEBUG [StandardServletEnvironment] Adding [jndiProperties] PropertySource with lowest search precedence
15:44:33,832 DEBUG [StandardServletEnvironment] Adding [jndiProperties] PropertySource with lowest search precedence
15:44:33,832 DEBUG [StandardServletEnvironment] Adding [systemProperties] PropertySource with lowest search precedence
15:44:33,832 DEBUG [StandardServletEnvironment] Adding [systemProperties] PropertySource with lowest search precedence
15:44:33,834 DEBUG [StandardServletEnvironment] Adding [systemEnvironment] PropertySource with lowest search precedence
15:44:33,834 DEBUG [StandardServletEnvironment] Adding [systemEnvironment] PropertySource with lowest search precedence
15:44:33,834 DEBUG [StandardServletEnvironment] Initialized StandardServletEnvironment with PropertySources [servletConfigInitParams,servletContextInitParams,jndiProperties,systemProperties,systemEnvironment]
15:44:33,834 DEBUG [StandardServletEnvironment] Initialized StandardServletEnvironment with PropertySources [servletConfigInitParams,servletContextInitParams,jndiProperties,systemProperties,systemEnvironment]
15:44:33,837  INFO [XmlWebApplicationContext] Refreshing Root WebApplicationContext: startup date [Thu Apr 26 15:44:33 BRT 2012]; root of context hierarchy
15:44:33,837  INFO [XmlWebApplicationContext] Refreshing Root WebApplicationContext: startup date [Thu Apr 26 15:44:33 BRT 2012]; root of context hierarchy
15:44:33,852 DEBUG [StandardServletEnvironment] Replacing [servletContextInitParams] PropertySource with [servletContextInitParams]
15:44:33,852 DEBUG [StandardServletEnvironment] Replacing [servletContextInitParams] PropertySource with [servletContextInitParams]
15:44:33,952 DEBUG [StandardEnvironment ] Initializing new StandardEnvironment
15:44:33,953 DEBUG [StandardEnvironment ] Adding [systemProperties] PropertySource with lowest search precedence
15:44:33,953 DEBUG [StandardEnvironment ] Adding [systemEnvironment] PropertySource with lowest search precedence
15:44:33,953 DEBUG [StandardEnvironment ] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
15:44:33,955 DEBUG [StandardEnvironment ] Initializing new StandardEnvironment
15:44:33,955 DEBUG [StandardEnvironment ] Adding [systemProperties] PropertySource with lowest search precedence
15:44:33,955 DEBUG [StandardEnvironment ] Adding [systemEnvironment] PropertySource with lowest search precedence
15:44:33,955 DEBUG [StandardEnvironment ] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
15:44:33,974  INFO [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
15:44:33,976 DEBUG [DefaultDocumentLoader] Using JAXP provider [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl]
15:44:33,996 DEBUG [PluggableSchemaResolver] Loading schema mappings from [META-INF/spring.schemas]
15:44:34,003 DEBUG [PluggableSchemaResolver] Loaded schema mappings: {http://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd, http://www.springframework.org/schema/task/spring-task.xsd=org/springframework/scheduling/config/spring-task-3.1.xsd, http://www.springframework.org/schema/beans/spring-beans-3.1.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd, http://www.springframework.org/schema/cache/spring-cache.xsd=org/springframework/cache/config/spring-cache-3.1.xsd, http://www.springframework.org/schema/aop/spring-aop-3.0.xsd=org/springframework/aop/config/spring-aop-3.0.xsd, http://www.springframework.org/schema/task/spring-task-3.1.xsd=org/springframework/scheduling/config/spring-task-3.1.xsd, http://www.springframework.org/schema/aop/spring-aop-2.0.xsd=org/springframework/aop/config/spring-aop-2.0.xsd, http://www.springframework.org/schema/tool/spring-tool-2.5.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd, http://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd, http://www.springframework.org/schema/jee/spring-jee-2.5.xsd=org/springframework/ejb/config/spring-jee-2.5.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd=org/springframework/jdbc/config/spring-jdbc-3.1.xsd, http://www.springframework.org/schema/tool/spring-tool-3.1.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd, http://www.springframework.org/schema/jee/spring-jee-3.1.xsd=org/springframework/ejb/config/spring-jee-3.1.xsd, http://www.springframework.org/schema/aop/spring-aop.xsd=org/springframework/aop/config/spring-aop-3.1.xsd, http://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans-2.0.xsd, http://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd, http://www.springframework.org/schema/task/spring-task-3.0.xsd=org/springframework/scheduling/config/spring-task-3.0.xsd, http://www.springframework.org/schema/tx/spring-tx-2.5.xsd=org/springframework/transaction/config/spring-tx-2.5.xsd, http://www.springframework.org/schema/context/spring-context-2.5.xsd=org/springframework/context/config/spring-context-2.5.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd=org/springframework/jdbc/config/spring-jdbc-3.0.xsd, http://www.springframework.org/schema/tool/spring-tool-3.0.xsd=org/springframework/beans/factory/xml/spring-tool-3.0.xsd, http://www.springframework.org/schema/tx/spring-tx.xsd=org/springframework/transaction/config/spring-tx-3.0.xsd, http://www.springframework.org/schema/tool/spring-tool-2.0.xsd=org/springframework/beans/factory/xml/spring-tool-2.0.xsd, http://www.springframework.org/schema/util/spring-util-2.5.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd, http://www.springframework.org/schema/lang/spring-lang.xsd=org/springframework/scripting/config/spring-lang-3.1.xsd, http://www.springframework.org/schema/lang/spring-lang-2.5.xsd=org/springframework/scripting/config/spring-lang-2.5.xsd, http://www.springframework.org/schema/jee/spring-jee-3.0.xsd=org/springframework/ejb/config/spring-jee-3.0.xsd, http://www.springframework.org/schema/jee/spring-jee-2.0.xsd=org/springframework/ejb/config/spring-jee-2.0.xsd, http://www.springframework.org/schema/context/spring-context-3.1.xsd=org/springframework/context/config/spring-context-3.1.xsd, http://www.springframework.org/schema/util/spring-util-3.1.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd, http://www.springframework.org/schema/lang/spring-lang-3.1.xsd=org/springframework/scripting/config/spring-lang-3.1.xsd, http://www.springframework.org/schema/cache/spring-cache-3.1.xsd=org/springframework/cache/config/spring-cache-3.1.xsd, http://www.springframework.org/schema/context/spring-context.xsd=org/springframework/context/config/spring-context-3.1.xsd, http://www.springframework.org/schema/jee/spring-jee.xsd=org/springframework/ejb/config/spring-jee-3.1.xsd, http://www.springframework.org/schema/aop/spring-aop-2.5.xsd=org/springframework/aop/config/spring-aop-2.5.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc.xsd=org/springframework/jdbc/config/spring-jdbc-3.1.xsd, http://www.springframework.org/schema/tx/spring-tx-2.0.xsd=org/springframework/transaction/config/spring-tx-2.0.xsd, http://www.springframework.org/schema/aop/spring-aop-3.1.xsd=org/springframework/aop/config/spring-aop-3.1.xsd, http://www.springframework.org/schema/tx/spring-tx-3.0.xsd=org/springframework/transaction/config/spring-tx-3.0.xsd, http://www.springframework.org/schema/context/spring-context-3.0.xsd=org/springframework/context/config/spring-context-3.0.xsd, http://www.springframework.org/schema/tool/spring-tool.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd, http://www.springframework.org/schema/util/spring-util-3.0.xsd=org/springframework/beans/factory/xml/spring-util-3.0.xsd, http://www.springframework.org/schema/lang/spring-lang-3.0.xsd=org/springframework/scripting/config/spring-lang-3.0.xsd, http://www.springframework.org/schema/util/spring-util-2.0.xsd=org/springframework/beans/factory/xml/spring-util-2.0.xsd, http://www.springframework.org/schema/lang/spring-lang-2.0.xsd=org/springframework/scripting/config/spring-lang-2.0.xsd, http://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd}
15:44:34,006 DEBUG [PluggableSchemaResolver] Found XML schema [http://www.springframework.org/schema/beans/spring-beans-3.0.xsd] in classpath: org/springframework/beans/factory/xml/spring-beans-3.0.xsd
[b]
15:44:34,064 DEBUG [DefaultBeanDefinitionDocumentReader] Loading bean definitions
15:44:34,107 DEBUG [XmlBeanDefinitionReader] Loaded 2 bean definitions from location pattern [/WEB-INF/applicationContext.xml]
15:44:34,107 DEBUG [XmlWebApplicationContext] Bean factory for Root WebApplicationContext: org.springframework.beans.factory.support.DefaultListableBeanFactory@1dfa490: defining beans [dataSource,indexDAOImpl]; root of factory hierarchy
15:44:34,107 DEBUG [XmlWebApplicationContext] Bean factory for Root WebApplicationContext: org.springframework.beans.factory.support.DefaultListableBeanFactory@1dfa490: defining beans [dataSource,indexDAOImpl]; root of factory hierarchy
15:44:34,195 DEBUG [XmlWebApplicationContext] Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@10948bd]
15:44:34,195 DEBUG [XmlWebApplicationContext] Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@10948bd]
15:44:34,200 DEBUG [XmlWebApplicationContext] Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@77622b]
15:44:34,200 DEBUG [XmlWebApplicationContext] Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@77622b]
15:44:34,210 DEBUG [UiApplicationContextUtils] Unable to locate ThemeSource with name 'themeSource': using default [org.springframework.ui.context.support.ResourceBundleThemeSource@1bcfbeb]
15:44:34,210  INFO [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1dfa490: defining beans [dataSource,indexDAOImpl]; root of factory hierarchy
15:44:34,210 DEBUG [DefaultListableBeanFactory] Creating shared instance of singleton bean 'dataSource'
15:44:34,210 DEBUG [DefaultListableBeanFactory] Creating instance of bean 'dataSource'
[/b]
15:44:34,247 DEBUG [DefaultListableBeanFactory] Eagerly caching bean 'dataSource' to allow for resolving potential circular references
log4j:WARN No appenders could be found for logger (org.springframework.jdbc.datasource.DriverManagerDataSource).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
15:44:34,346 DEBUG [DefaultListableBeanFactory] Finished creating instance of bean 'dataSource'
15:44:34,347 DEBUG [DefaultListableBeanFactory] Creating shared instance of singleton bean 'indexDAOImpl'
15:44:34,347 DEBUG [DefaultListableBeanFactory] Creating instance of bean 'indexDAOImpl'
15:44:34,363 DEBUG [DefaultListableBeanFactory] Eagerly caching bean 'indexDAOImpl' to allow for resolving potential circular references
15:44:34,363 DEBUG [DefaultListableBeanFactory] Returning cached instance of singleton bean 'dataSource'
15:44:34,406 DEBUG [DefaultListableBeanFactory] Invoking afterPropertiesSet() on bean with name 'indexDAOImpl'
15:44:34,406 DEBUG [DefaultListableBeanFactory] Finished creating instance of bean 'indexDAOImpl'

Não é isso que está sendo informado nas linhas em negrito ?

Um abraço obrigado.

4 Respostas

Lucas_Cavalcanti

se vc registrou um bean no xml do spring, vc não pode anotá-lo com o @Component do VRaptor… só tirar que vai funcionar.

Lucas_Cavalcanti

se ainda assim não funcionar, mova o applicationContext.xml pro classpath (geralmente pasta src ou src/main/resources)

marcelomello

PÔ Lucas, Na MOSCA,

Retirei o @Component do meu daoImpl e o meu debug funfou.
Porém, o a n _ _ aqui, gostaria de saber se eu retirar o código abaixo do appContext.xml
Como faço a injeção? Basta anotar novamente com @Component?

<bean id="indexDAOImpl" class="br.com.tecnopolis.vraptorspringjdbc.dao.impl.IndexDAOImpl">  
	<property name="dataSource" ref="dataSource" />  
</bean>

Aí como que fica a injeção do dataSource acima, na minha classe?

Obrigado mais uma vez pela pronta e certeira resposta

Lucas_Cavalcanti

se vc tirar essa declaração do bean, vc anota a classe com @Component, recebe um DataSource no construtor e faz um setDataSource(dataSource);

Criado 26 de abril de 2012
Ultima resposta 26 de abr. de 2012
Respostas 4
Participantes 2