Factory Spring erro

3 respostas
acjZer0

opa galera desculpa o incomodo, porem to com uma dificuldade no spring, sera que vocês podem me ajudar?

application-model.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"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd">

	 
	 <bean id="categoria" class="model.Categoria" />
	 <bean id="endereco" class="model.Endereco" />
	 <bean id="lance" class="model.Lance" />
	 <bean id="post" class="model.Post" />
	 <bean id="projeto" class="model.Projeto" />
	 <bean id="tipolance" class="model.TipoLance" />
	 <bean id="usuario" class="model.Usuario" />
</beans>
application-factorys.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"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd">

<bean id="modelfactory" class="org.springframework.context.support.ClassPathXmlApplicationContext">
        <constructor-arg>
            <list>
                <value>application-model.xml</value>
            </list>
        </constructor-arg>
</bean>
</beans>
ServiceLocator.java
package utils;

import org.apache.commons.lang.NullArgumentException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.access.BeanFactoryLocator;
import org.springframework.beans.factory.access.BeanFactoryReference;
import org.springframework.context.access.ContextSingletonBeanFactoryLocator;
 
 
public class ServiceLocator {
	
	private static final ServiceLocator INSTANCE = new ServiceLocator();
		
	private final BeanFactoryReference factoryReference;
	
	
	private ServiceLocator() {
		BeanFactoryLocator factoryLocator = ContextSingletonBeanFactoryLocator.getInstance();
		factoryReference = factoryLocator.useBeanFactory("modelfactory");
		
	
	}
		
	public static ServiceLocator getInstance() {
		return INSTANCE;
	}
	
	public Object getObject(String name) {
		try {
			if (name == null) {
				throw new NullArgumentException("name");
			}
			BeanFactory factory = this.factoryReference.getFactory();
			return factory.getBean(name);
		} catch (RuntimeException exception) {
			throw exception;
		}
	}

}

Problema: não consigo fazer minha fabrica funcionar gostaria de ajuda para fazer isso.
ultimo erro que obtive :org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'modelfactory' is defined.
status: atualmente estou acessando a classe via scriplet mesmo só para testes.

desde já muito obrigado a todos :D .

3 Respostas

acjZer0

ao acessar o console mostra a seguinte menssagem:

14:54:43,106 INFO [STDOUT] 2009-09-21 14:54:43,106 [http-localhost%2F127.0.0.1-8080-1] INFO org.springframework.context.support.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@15cda11: display name [org.springframework.context.support.ClassPathXmlApplicationContext@15cda11]; startup date [Mon Sep 21 14:54:43 GMT-03:00 2009]; root of context hierarchy
14:54:43,112 INFO [STDOUT] 2009-09-21 14:54:43,112 [http-localhost%2F127.0.0.1-8080-1] INFO org.springframework.context.support.ClassPathXmlApplicationContext - Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@15cda11]: org.springframework.beans.factory.support.DefaultListableBeanFactory@f8f6d0
14:54:43,113 INFO [STDOUT] 2009-09-21 14:54:43,113 [http-localhost%2F127.0.0.1-8080-1] INFO org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@f8f6d0: defining beans []; root of factory hierarchy
14:54:43,147 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘modelfactory’ is defined

acjZer0

web xml:

<?xml version="1.0" encoding="UTF-8"?>

<web-app id="WebApp_ID" version="2.4"
 xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 
 
<display-name>Lance Digital</display-name>
      
<!--  Listner Tiles -->
<listener>
		<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>

     <!--  Listner Spring -->
<listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
 
 
<!--  Inicialização de contexto Spring -->    
<context-param>    
    <param-name>contextConfigLocation</param-name>
        <param-value>
        	WEB-INF/classes/application-factorys.xml
        	WEB-INF/classes/applicationContext.xml
        	WEB-INF/classes/application-aspectos.xml
        	WEB-INF/classes/application-daos.xml
        	WEB-INF/classes/application-services.xml
        	WEB-INF/classes/application-actions.xml
        	WEB-INF/classes/application-security.xml
        	WEB-INF/classes/application-model.xml
        </param-value>
    
   </context-param>
 
  
<!--  Inicialização de contexto Tiles 2 -->   

<context-param>
   <param-name>
     org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
   </param-name>
   <param-value>
    /WEB-INF/classes/tiles.xml
   </param-value>
</context-param>


<!-- Filtros -->
<filter>
  <filter-name>struts2</filter-name>
     <filter-class>
       org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
     </filter-class>
</filter>
    
    
<!-- Mapeamento dos filtros -->
<filter-mapping>
  <filter-name>struts2</filter-name>
   <url-pattern>/*</url-pattern>
 </filter-mapping>
    
<!-- Pagina de boas vindas -->
    
<welcome-file-list>
  <welcome-file>/principal.action</welcome-file>
 </welcome-file-list>

<!-- Login Config -->

<login-config>
  <auth-method>BASIC</auth-method>
</login-config>


</web-app>
acjZer0

Resolvido

Resposta que obtive no Forum http://forum.springsource.org:

chelu

Hi,
Try with ContextSingletonBeanFactoryLocator.getInstance(“ap plication-factorys.xml
”)
or change application-factorys.xml to default selector name beanRefFactory.xml

Criado 21 de setembro de 2009
Ultima resposta 21 de set. de 2009
Respostas 3
Participantes 1