Bean não definido (spring)

5 respostas
F

Boa tarde,
tenho um bean “testeDAO” declarado no applicationContext mas a spring parece não enxergar.

O fato é que ele é atributo de um outro bean (referencia) e é exibida a segunte mensagem:

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘modelService’ defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Can’t resolve reference to bean ‘testeDAO’ while setting property ‘testeDAO’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘testeDAO’ is defined
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘testeDAO’ is defined

<bean id="modelService"
		  class="br.com.service.business.model.impl.ModelServiceImpl"> 
    		<property name="testeDAO"><ref bean="testeoDAO"/></property>	 	
	</bean>

porque testeoDAO não está definido se também declarei ele, so que no applicationContext-hibernate?

<bean id="testeDAO"
        class="br.com.service.data.dao.impl.hibernate.TesteDAOHibernateImpl" >                
</bean>

obrigado.

5 Respostas

E

você poderia postar o seu web.xml !

V

O applicationContext.xml nao conhece o outro xml. Colque um import no applicationContext.xml

&lt;import resource="classpath:applicationContext-hibernate.xml" /&gt;

&lt;bean id="modelService"
		  class="br.com.service.business.model.impl.ModelServiceImpl"&gt; 
    		&lt;property name="testeDAO"&gt;&lt;ref bean="testeoDAO"/&gt;&lt;/property&gt;	 	
&lt;/bean&gt;
F
<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
			/WEB-INF/applicationContext.xml
			
			/WEB-INF/applicationContext-log.xml
			/WEB-INF/applicationContext-filters.xml
			/WEB-INF/applicationContext-error.xml
			/WEB-INF/applicationContext-object.xml
			/WEB-INF/applicationContext-mail.xml
			/WEB-INF/applicationContext-session.xml
			/WEB-INF/applicationContext-security.xml
			/WEB-INF/applicationContext-hibernate-ibpfd001.xml			
			/WEB-INF/applicationContext-daos.xml
			/WEB-INF/applicationContext-pdc.xml
			/WEB-INF/applicationContext-pdc-connectors.xml
			/WEB-INF/applicationContext-commarea.xml			
			/WEB-INF/servicos/applicationContext-servicos-beans.xml
			/WEB-INF/servicos/applicationContext-servicos-categorias.xml
			/WEB-INF/servicos/applicationContext-servicos.xml
			/WEB-INF/servicos/applicationContext-itens.xml
			/WEB-INF/application-label.xml
						
		</param-value>
	</context-param>
E

Outra forma seria você configurar os seus applicationContext no web.xml, para subir junto com a aplicação !!

&lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt; /WEB-INF/applicationContext.xml /WEB-INF/applicationContext-daos.xml /WEB-INF/applicationContext-security.xml /WEB-INF/applicationContext-monitor.xml /WEB-INF/applicationContext-log.xml /WEB-INF/applicationContext-filters.xml /WEB-INF/applicationContext-alert.xml /WEB-INF/applicationContext-error.xml /WEB-INF/applicationContext-object.xml /WEB-INF/applicationContext-session.xml /WEB-INF/applicationContext-pdc.xml /WEB-INF/applicationContext-pdc-connectors.xml &lt;/param-value&gt; &lt;/context-param&gt;

F

Valeu pessoal, só faltava mesmo a referencia no applicationContext.xml ao hibernate.

[]

Criado 7 de janeiro de 2010
Ultima resposta 11 de jan. de 2010
Respostas 5
Participantes 3