I'm having a problem with this. All the DAOs and Services are null, I don't how to fix that :(
Here is the config part in web.xml
...
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
...
and in applicationContext.xml
<context:component-scan base-package="com.tipytut" />
<context:annotation-config />
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean
class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>/WEB-INF/classes/tipytut.properties</value>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<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="MYSQL" />
<property name="showSql" value="true" />
</bean>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
I have a DAO like this:
@Repository("tagDAO")
@Transactional
public class TagDAOImpl extends JpaDAO implements TagDAO {
public List<Tag> getTags() {
return getList("SELECT t FROM Tag t");
}
}
... and the Service
@Service("managementService")
@Transactional
public class ManagementServiceImpl implements ManagementService {
@Autowired
private TagDAO tagDAO;
public List<Tag> getTags() {
return tagDAO.getTags();
}
}
When I call that service in my Controller, it's always NULL
@Autowired
private ManagementService managementService;
public List<Tag> getTags() {
try {
managementService.getTags();
} catch (Exception ex) {
ex.printStackTrace();
}
return tags;
}
Any help will be appreciated.
UPDATED: I uploaded my project HERE (just the initial part, very simple), so everyone can take a look. Hope someone can figure out what is wrong with that. :(
I forgot to update my question, finally figured it out! I forgot to add dependency for struts2-spring-plugin
, the problem is that I got no error message about this X-(
Hope this will help someone ^^