F
ff_ff
Unregistered / Unconfirmed
GUEST, unregistred user!
我有个Dao类SubjectDAO,
在Spring配置文件中是这样的.
..
<bean id="subjectDAO"
class="com.hibernate.SubjectDAO">
<property name="sessionFactory">
<ref bean="sessionFactory"
/>
</property>
</bean>
..
关于sessionFactory:
在Spring配置文件中是这样的.
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource"
/>
</property>
<property name="mappingResources">
<list>
<value>com/test/Hibernate/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
那么,我在SubjectDAO 中如何引用定义个sessionFactory这个属性呢?
我写成这样:
LocalSessionFactoryBean sessionFactory;
public void setSessionFactory(LocalSessionFactoryBean sessionFactory){
this.sessionFactory = sessionFactory;
}
public SessionFactory getSessionFactory(){
return sessionFactory;
}
对吗?
第一次用Spring,请大家关照.
在Spring配置文件中是这样的.
..
<bean id="subjectDAO"
class="com.hibernate.SubjectDAO">
<property name="sessionFactory">
<ref bean="sessionFactory"
/>
</property>
</bean>
..
关于sessionFactory:
在Spring配置文件中是这样的.
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource"
/>
</property>
<property name="mappingResources">
<list>
<value>com/test/Hibernate/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
那么,我在SubjectDAO 中如何引用定义个sessionFactory这个属性呢?
我写成这样:
LocalSessionFactoryBean sessionFactory;
public void setSessionFactory(LocalSessionFactoryBean sessionFactory){
this.sessionFactory = sessionFactory;
}
public SessionFactory getSessionFactory(){
return sessionFactory;
}
对吗?
第一次用Spring,请大家关照.