我有一個JSF 2.0應用程序,並且我正在集成Spring,因此我可以使用hibernateTemplate。我已經諮詢了關於JSF集成的Spring documentation,並已採取步驟進行設置。我的所有bean類都擴展了一個名爲SuperBean的抽象超類。 SuperBean是需要的注入點,使我無需在Spring中聲明所有的bean。我希望只是將其聲明爲abstract =「true」,並且任何擴展了SuperBean類的子類都將注入dao。在運行時它是空的。Spring沒有將DAO注入到具有抽象超類的JSF託管bean中
<bean id="serviceTemplate" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<props>
<prop key="*"/>
</props>
</property>
</bean>
<bean id="daoServiceTarget" class="com.example.service.DaoService">
<property name="mainDAO" ref="mainDAO"/>
</bean>
<bean id="daoService" parent="serviceTemplate">
<property name="target" ref="daoServiceTarget"/>
</bean>
<bean id="superBean" class="com.example.beans.SuperBean" abstract="true">
<property name="daoService" ref="daoService"/>
</bean>
我可以簡單地聲明這個超類SuperBean並期待Spring注入dao嗎?我不想在春季申報每個bean類。
我想替代選項(從性能角度來看)將不使用Spring bean,而是將DAO聲明爲@applicationScoped並使用JEE的CDI將它們注入到SuperBean類中。這會更好地表現明智嗎?
我添加了serviceTemplate bean定義。這只是春季提供的另一個抽象類。我想避免在春季定義每個bean。我的SuperBean類有一個方法setDaoService(DaoService dao){// set attr}。所有屬於子類的bean都應該有DAO,因爲SubBean是一個SuperBean。這可能嗎? – Adam 2011-04-12 03:05:03