Four dependency check modes of bean in spring

Source: Internet
Author: User

From: http://jnotnull.iteye.com/blog/153475

In the preceding example, we can see that an error is thrown if no matching is found by setting the dependency-check = "object" attribute. This is the type check.

Let's take a look at the dependency Check Mode in bean 4 in Spring: simple, object, all, none.
1 simple: Check the dependency of the basic type, struct type, and set.

Java code
  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <! Doctype beans public "-// spring // DTD bean // en"
  3. Http://www.springframework.org/dtd/spring-beans.dtd>
  4. <Beans>
  5. <Bean id = "helloworld" class = "com. jnotnull. helloworld"
  6. Autowire = "autodectect" dependency-check = "simple">
  7. <Bean>
  8. <Bean id = "date" class = "Java. util. Date">
  9. </Beans>

2 object: Check the Java code of the dependent object

  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <! Doctype beans public "-// spring // DTD bean // en"
  3. Http://www.springframework.org/dtd/spring-beans.dtd>
  4. <Beans>
  5. <Bean id = "helloworld" class = "com. jnotnull. helloworld"
  6. Autowire = "autodectect" dependency-check = "object">
  7. <Bean>
  8. <Bean id = "date" class = "Java. util. Date">
  9. </Beans>

3 All: Check all attributes in Java code

  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <! Doctype beans public "-// spring // DTD bean // en"
  3. Http://www.springframework.org/dtd/spring-beans.dtd>
  4. <Beans>
  5. <Bean id = "helloworld" class = "com. jnotnull. helloworld"
  6. Autowire = "autodectect" dependency-check = "all">
  7. <Bean>
  8. <Bean id = "date" class = "Java. util. Date">
  9. </Beans>

4 none: no dependency check: Java code

  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <! Doctype beans public "-// spring // DTD bean // en"
  3. Http://www.springframework.org/dtd/spring-beans.dtd>
  4. <Beans>
  5. <Bean id = "helloworld" class = "com. jnotnull. helloworld"
  6. Autowire = "autodectect" dependency-check = "NONE">
  7. <Bean>
  8. <Bean id = "date" class = "Java. util. Date">
  9. </Beans>

From this we can see that dependency check is generally used together with automatic loading. If there is no automatic load, there is no need for dependency check.

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.