Amigos estou tentando usar Spring com o Struts 1 porem nao consigo o meu web.xml esta assim
[code]<?xml version="1.0" encoding="UTF-8"?>
ControleFuncionario
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
<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>
[/code]
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:
[code]<?xml version="1.0" encoding="UTF-8"?>
<bean id="empresaService" class="br.com.controlefuncionario.service.EmpresaService">
</bean>
<bean id="empresaAction" class="br.com.controlefuncionario.action.EmpresaAction">
</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>
[/code]
e a minha classe esta assim:
[code]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;
}
}
[/code]
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