Pessoal, eu jah trabalhava com o Struts 1, e agora estou criando com Struts 2 e Spring.
Meu projeto está com Struts 2, Spring e Hibernate, fazendo a Action chamar um Service que chama o DAO.
Mas estou com um grande problema: Na action, nao sei como criar o acesso ao meu service bean.
Com o request e result, eu consegui através do " implements RequestAware, ParameterAware " na minha classe de action…
Meu codigo está assim:
public class OrdemServicoAction extends DispatchActionSupport implements RequestAware, ParameterAware {
private Log log = LogFactory.getLog(this.getClass());
private Map request;
private Map parameter;
private String AHAM;
public OrdemServicoAction() {
}
public String defaultMethod() {
log.debug("getServletRequest getAHAM=" + getAHAM() );
log.debug("getServletRequest parameter.getAHAM=" + parameter.get("AHAM") );
log.debug("entering 'delete' method...");
WebApplicationContext ctx = getWebApplicationContext();
log.debug("applicationContext exist ? " + (ctx!=null));
OrdemServicoService mgr = (OrdemServicoService) ctx.getBean("ordemServicoService");
log.debug("ordemServicoService exist ? " + (mgr!=null));
return Action.SUCCESS;
}
E a variavel ctx está sempre NULL;
Meu applicationContext:
<?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: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/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" autowire="autodetect" />
<bean name="usuarioLogado" class="thabit.web.DadosUsuarioLogado" scope="session" autowire="autodetect" >
<aop:scoped-proxy/>
</bean>
<import resource="application-services.xml" />
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="POSTGRESQL" />
<property name="showSql" value="true" />
</bean>
</property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
...
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<import resource="application-actions.xml"/>
</beans>
O application-services.xml
...
<!-- SERVICES -->
<bean id="personService" class="thabit.persist.service.impl.PersonServiceImpl" autowire="autodetect"/>
<bean id="ordemServicoService" class="thabit.persist.service.impl.OrdemServicoServiceImpl" autowire="autodetect" />
</beans>
e o application-actions.xml
...
<!-- STRUTS2 ACTIONS -->
<bean id="personAction" scope="prototype" class="thabit.web.action.PersonAction" >
</bean>
<bean id="ordemServicoAction" scope="prototype" class="thabit.web.action.OrdemServicoAction">
</bean>
...
Na real eu poderia passar em cada action seu service correto por injeção de classes, por parametro ou pelo constructor da classe... mas pq o "getWebApplicationContext" nao funciona sendo que minha action extende "DispatchActionSupport" ?
Obrigado …
