Spring implementation without annotations for automatic injection

Source: Internet
Author: User

XML configuration

Procedure: Set automatic assembly of the package--using Include-filter filter type to select the Regex as regular expression-->expression is the expression is the limit condition

1<?xml version= "1.0" encoding= "UTF-8"?>2<beans xmlns= "Http://www.springframework.org/schema/beans"3Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4xmlns:context= "Http://www.springframework.org/schema/context"5xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-2.5.xsd6http//Www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsd">7<!--for automatic assembly--8<context:component-scan base- Package= "Cn.lonecloud" >9<!--contains the DAO layer type type under a package the Regex represents the restriction conditions that the regular expression needs to set--Ten<!--some of the DAO layers under this expression that use this representation can be directly used without annotations-- One<context:include-filter type= "regex" expression= "cn.lonecloud.dao.*dao.*"/> A<context:include-filter type= "regex" expression= "cn.lonecloud.service.*service.*"/> -<!--classes that are configured under this type will not be registered with the spring container- -<context:exclude-filter type= "regex" expression= "Cn.lonecloud.service.TestService"/> the</context:component-scan> -  -</beans>

DAO layer

1  Package Cn.lonecloud.dao; 2 3  Public class Testdao {4      Public void Test01 () {5         System.out.println ("Dao"); 6     }7 }

Service Layer

1  PackageCn.lonecloud.service;2 3 Importorg.springframework.beans.factory.annotation.Autowired;4 5 ImportCn.lonecloud.dao.TestDao;6 7  Public classTestservice {8     9 @AutowiredTen Testdao Testdao; One      A      Public voidTest01 () { - testdao.test01 (); -     } the}

Test layer

1  Packagecn.lonecloud.test;2 3 ImportOrg.junit.Before;4 Importorg.junit.Test;5 ImportOrg.springframework.context.support.ClassPathXmlApplicationContext;6 7 ImportCn.lonecloud.service.TestService;8 9  Public classTestmain {TenClasspathxmlapplicationcontext xmlapplicationcontext=NULL; One @Before A      Public voidinit () { -xmlapplicationcontext=NewClasspathxmlapplicationcontext ("Applicationcontext.xml"); -     } the @Test -      Public voidTest01 () { -Testservice Testservice=xmlapplicationcontext.getbean (Testservice.class); - testservice.test01 (); +     } -}

Spring implementation without annotations for automatic injection

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.