Multiple databases are used in spring at the same time.

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.