Java Study Notes 2-Batch use of Spring Autowired

Source: Internet
Author: User

Before writing batch operations, write an example of a single usage for comparison. The following code is provided: 1. bean file configuration: [html] www.2cto.com <bean id = "userDao" class = "... "/> <bean id =" userService "class = "... "> <property name =" userDao "> <ref bean =" userDao "/> </property> </bean> 2. java code [java] @ Autowired private UserDao userdao; in this way, you can call the methods in UserDao because dao and service have multiple methods in a project, this requires many similar configurations. The following uses the service as an example to describe how to implement batch automatic loading. We assume that all service files are placed on com. test. under biz 1. directory structure 2. bean file configuration [html] <? Xml version = "1.0" encoding = "UTF-8"?> <Beans xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns = "http://www.springframework.org/schema/beans" xmlns: context = "http://www.springframework.org/schema/context" xmlns: p = "http://www.springframework.org/schema/p" xsi: schemaLocation = "http://www.springframework.org/schema/beans http: // localhost: 8080/schema/www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework. Org/schema/context http: // localhost: 8080/schema/www.springframework.org/schema/context/spring-context.xsd "default-autowire =" byName "> ① <context: component-scan base-package =" com. test. biz. impl "> ② <context: include-filter type =" regex "expression = ". * Impl "/> ③ </context: component-scan> </beans> ① set automatic loading to the file configured by name ② scanned package ③ 3. user. java [java] package com. test. biz; public interface User {String getName ();} 4. userImpl. java [java] package com. test. biz. impl; import com. test. biz. user; public class UserImpl implements User {private String name = "aaa"; public String getName () {return this. name ;}} 5. use [Java] @ Autowired private User in java; 6. this is done. If there is a new service, you only need to write the server File in the biz directory. You don't need to configure the bean file any more ~

Related Article

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.