下面是我的課和xml:彈簧自動連接不工作,讓'applicationDao`爲空
@Component
@Service("ApplicationService")
public class ApplicationServiceImpl implements ApplicationService{
public ApplicationDao getApplicationDao() {
return applicationDao;
}
public void setApplicationDao(ApplicationDao applicationDao) {
this.applicationDao = applicationDao;
}
@Autowired
private ApplicationDao applicationDao;
// some methods..
}
@Service
public interface ApplicationService {
// methods...
}
@Component
@Repository("ApplicationDao")
public class ApplicationDaoImpl implements ApplicationDao {
@Autowired
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
// other methods...
}
public interface ApplicationDao {
// methods...
}
xml文件:
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven/>
<context:component-scan base-package="com" />
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<!-- <property name="dataSource" ref="dataSource" /> -->
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<bean id="ApplicationDao" class="com.dao.impl.ApplicationDaoImpl"/>
<bean id="ApplicationService" class="com.service.impl.ApplicationServiceImpl"/>
這裏自動裝配不working.in ApplicationServiceImpl
,我越來越applicationDao
爲空。沒有在ApplicationDaoImpl中測試sessionFactory
。
我知道如果我使用@Component,那麼xmnl中的bean聲明不是必需的。
你可以展示你所看到的棧跟蹤嗎? – geoand
嘗試添加'''到你的xml文件 –
Jens
沒有例外。打印道對象時,我只是變爲空。 – VJS