spring xml based on IOC environment to build and entry

Pom.xml configuration dependency of

    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.0.2.RELEASE</version>
        </dependency>
    </dependencies>

Creating the resources in bean.xml

Import Constraints

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>

To create objects to manage to spring

unique id flag acquisition, class of fully qualified class name to be reflected

    <! - to create objects to the spring Administration -> 
    <bean the above mentioned id = "the AccountService" class = "cn.flypig666.service.impl.AccountServiceImpl"> </ bean> 
    <bean the above mentioned id = "AccountDao" class = " cn.flypig666.dao.impl.AccountDaoImpl "> </ bean>

use:

. 1  public  static  void main (String [] args) {
 2  
. 3          // 1. Obtaining Core container object 
. 4          the ApplicationContext AC = new new the ClassPathXmlApplicationContext ( "bean.xml" );
 . 5          // 2. The acquisition Bean object ID 
. 6          IAccountService AS = (IAccountService) ac.getBean ( "AccountService" );
 . 7          // be obtained by strong rotation IAccountDao bytecode 
. 8          IAccountDao ac.getBean AD = ( "AccountDao", IAccountDao. class );
 . 9          System.out.println (AS );
 10          System.out.println (AD);
 . 11  
12 is      }

 

Guess you like

Origin www.cnblogs.com/flypig666/p/11511188.html