Struts 1 + Spring

0 respostas
fabioebner

Amigos estou tentando usar Spring com o Struts 1 porem nao consigo o meu web.xml esta assim

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>ControleFuncionario</display-name>
    
   <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
            <param-name>config</param-name>
            <param-value>/WEB-INF/struts-config/struts-config.xml</param-value>
        </init-param>
  </servlet>
   
      <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
  <!--
  	<welcome-file-list>
		<welcome-file>jsp/index.jsp</welcome-file>
	</welcome-file-list>
   -->
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
 <!-- Inicialização do Contexto do Spring -->
	<context-param>  
         <param-name>contextConfigLocation</param-name>  
         <param-value>  
             /WEB-INF/applicationContext.xml  
         </param-value>  
     </context-param>  
   
     <listener>  
         <listener-class>  
             org.springframework.web.context.ContextLoaderListener  
         </listener-class>  
     </listener>  	
     
     <listener>  
         <listener-class>  
             org.springframework.web.context.request.RequestContextListener  
         </listener-class>        
     </listener>  
  
   
</web-app>

ele nao da erro na hora de subir o servidor, porem na minha action ele nao esta funcionando o @AutoWired

meu applicationContext.xml esta assim:
<?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"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	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
		http://www.springframework.org/schema/aop
		http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
		http://www.springframework.org/schema/tx
		http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
		">

        <bean id="empresaService" class="br.com.controlefuncionario.service.EmpresaService">
        </bean>
		<bean id="empresaAction" class="br.com.controlefuncionario.action.EmpresaAction">
        </bean>        
<!-- 
        <bean id="loginJDL" class="br.com.dnasolution.licensa.guj.LoginJDL">
            <constructor-arg index="0" ><bean class="java.awt.Frame"/></constructor-arg>
            <constructor-arg index="1" value="true"/>
        </bean>

        <bean id="cadastroComputadorJDL" class="br.com.dnasolution.licensa.guj.CadastroComputadorJDL">
            <constructor-arg index="0" ><bean class="java.awt.Frame"/></constructor-arg>
            <constructor-arg index="1" value="true"/>
        </bean>

        <bean id="cadastroInstituicaoJDL" class="br.com.dnasolution.licensa.guj.CadastroInstituicaoJDL">
            <constructor-arg index="0" ><bean class="java.awt.Frame"/></constructor-arg>
            <constructor-arg index="1" value="true"/>
        </bean>
 -->
	<context:annotation-config/>
    <context:component-scan base-package="br"/>
	<aop:aspectj-autoproxy/>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" >
    <property name="dataSource">
     <ref local="c3p0DataSource"/>
    </property>
 	 <property name="annotatedClasses">
		    <list>
	 	        <value>br.com.controlefuncionario.entity.TbConfiguracao</value>
	 	        <value>br.com.controlefuncionario.entity.TbEmpresa</value>
	 	        <value>br.com.controlefuncionario.entity.TbFeriado</value>
	 	        <value>br.com.controlefuncionario.entity.TbFuncionario</value>
	 	        <value>br.com.controlefuncionario.entity.TbHistoricoProjeto</value>
	 	        <value>br.com.controlefuncionario.entity.TbPrioridade</value>
	 	        <value>br.com.controlefuncionario.entity.TbProjeto</value>
	 	        <value>br.com.controlefuncionario.entity.TbRendimentoFuncionario</value>
	 	     <!--  <value>br.com.dnasolution.licensa.entity.TbUsuario</value>
		       <value>br.com.dnasolution.licensa.entity.TbInstituicao</value>
		       -->  
		     </list>
		      
		   </property>

    	<property name="hibernateProperties">
    		<props>
 			    <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
    			<prop key="hibernate.connection.autocommit">false</prop>
    		</props>
        </property>

    </bean>

    <bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    	<property name="driverClass" value="org.postgresql.Driver"/>
    	<property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/banco"/>
    	<property name="user" value="postgres"/>
    	<property name="password" value="dadasd"/>
        <property name="initialPoolSize" value="5"/>
        <property name="minPoolSize" value="5"/>
        <property name="maxPoolSize" value="15"/>
        <property name="checkoutTimeout" value="1000"/>
        <property name="maxStatements" value="50"/>
        <property name="testConnectionOnCheckin" value="true"/>
        <property name="idleConnectionTestPeriod" value="60"/>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    	<property name="sessionFactory" ref="sessionFactory"/>
    </bean>
</beans>

e a minha classe esta assim:

package br.com.controlefuncionario.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.actions.DispatchAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import br.com.controlefuncionario.service.EmpresaService;

@Component
public class EmpresaAction extends DispatchAction {
	
	@Autowired
	private EmpresaService empresaService;
	
	public ActionForward iniciaEmpresa(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,HttpServletResponse response) throws Exception {
		try {
			//AgendaForm form = (AgendaForm) actionForm;
			//form.cleanForm();
			System.out.println(empresaService.toString());
			return (mapping.findForward("iniciaEmpresa"));
    	} catch (Exception e) {
    		request.setAttribute("urlFecharErro", "agenda.do?userAction=iniciaPesquisa");
        	e.printStackTrace();
        	throw new Exception(e);
		}
	}	
	
	public ActionForward cadastrarEmpersa(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,HttpServletResponse response) throws Exception {
		
		return null;
	}
}
na linha:
System.out.println(empresaService.toString());

Ele da erro de nullpointer, e a minha classe EmpresaService esta com o @Component tbm, alguem pode me ajudar?

obrigado

OBS: no application esta mapeado as duas classes, pois testei assim tbm e com o annotation e nao funcionou tbm

Criado 11 de maio de 2010
Respostas 0
Participantes 1