我们有一个带有单个数据库'dbMain'的应用程序,带有一组读写操作。
现在我们需要使用额外的数据库db1-db10进行只读操作,以便在SomeServiceImpl中使用。
问题是:
真的,不想使用JTA。 配置此类环境的正确方法是什么?
<tx:annotation-driven transaction-manager="dbMainTransactionManager"/>
<bean id="dbMainSessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dbMainDataSource"/>
...
</bean>
<bean id="dbMainTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="dbMainSessionFactory"/>
...
</bean>
@Repository
public class DBMainDAOImpl extends HibernateDaoSupport implements DBMainDAO {
@Resource(name = "dbMainSessionFactory")
protected void init(SessionFactory sessionFactory) throws Exception {
setSessionFactory(sessionFactory);
}
...
}
@Transactional
@Service
public class SomeServiceImpl implements SomeService {
@Autowired
private DBMainDAO dbMainDAO;
...
}
额外的dbs:
<bean id="db1SessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="db1DataSource"/>
...
</bean>
<bean id="db1TransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="db1SessionFactory"/>
...
</bean>
public class DB1DAOImpl extends HibernateDaoSupport implements DB1DAO {
@Resource(name = "db1SessionFactory")
protected void init(SessionFactory sessionFactory) throws Exception {
setSessionFactory(sessionFactory);
}
...
}
@Transactional
public class SomeServiceImpl implements SomeService {
@Autowired
private DBMainDAO dbMainDAO;
@Autowired
private DB1DAO db1DAO;
...
@Autowired
private DB10DAO db10DAO;
@PostConstruct init() {
...
}
...
}