Multiple databases are used in spring at the same time.
There is no problem in defining multiple databases under the deployment State. In this case, the spring container's dependency injection process for each bean component is searched by "name" by default (autowire = "byname ") yes, you only need to name different databases (datasource) and identify the databases by name in each DAO bean to meet the dependency injection requirements.
Spring also provides great convenience for integration testing. The JUnit-based testing framework generally inherits from:
Org. springframework. Test. abstracttransactionalspringcontexttests.
The dependency injection in the integrated test environment will fail when multiple databases are used.
Org. springframework. Beans. Factory. unsatisfieddependencyexception: unsatisfied dependency expressed through bean property 'datasource ':
No unique bean of Type [javax. SQL. datasource] is defined: Expected single matching bean but found 2: [effeccea, performanceb]
At... abstractautowirecapablebeanfactory. autowirebytype (abstractautowirecapablebeanfactory. Java: 1055)
......
Refer to
Abstracttransactionalspringcontexttests
Parent class
Abstractdependencyinjectionspringcontexttests
Description:
Public final void setautowiremode (INT autowiremode)
Set the autowire mode for test properties set by dependency injection.
The default is autowire_by_type. can be set to autowire_by_name or autowire_no instead.
See also:
Autowire_by_type, autowire_by_name, autowire_no
Call this method of the parent class in the constructor of the integration test case to set the dependency lookup/injection method to autowire_by_name. This avoids the initialization failure of the test environment and the dependency is correctly identified by the container.
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/jerryrt/archive/2008/05/22/2469790.aspx