zoukankan      html  css  js  c++  java
  • Document

    1.新建java project,然后新建spring文件夹,把六个基本的包复制进去,然后全选所有的包,右键bulid Path>add**;

    2.src所包含的class,beans.xml

     1 package com.java.service;
     2 
     3 import org.springframework.context.ApplicationContext;
     4 import org.springframework.context.support.ClassPathXmlApplicationContext;
     5 
     6 import com.java.test.HelloWorld;
     7 
     8 public class Test {
     9 
    10     public static void main(String[] args) {
    11         
    12         //连接beans
    13         ApplicationContext  ac=new ClassPathXmlApplicationContext("beans.xml");
    14         
    15         HelloWorld   helloWorld=(HelloWorld) ac.getBean("helloWorld");
    16         
    17         helloWorld.say();
    18     }
    19 
    20 }

     

    package com.java.service;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    import com.java.test.HelloWorld;
    
    public class Test {
    
        public static void main(String[] args) {
            
            //连接beans
            ApplicationContext  ac=new ClassPathXmlApplicationContext("beans.xml");
            
            HelloWorld   helloWorld=(HelloWorld) ac.getBean("helloWorld");
            
            helloWorld.say();
        }
    
    }

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <beans xmlns="http://www.springframework.org/schema/beans"
     3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4     xsi:schemaLocation="http://www.springframework.org/schema/beans
     5         http://www.springframework.org/schema/beans/spring-beans.xsd">
     6 
     7     <bean id="helloWorld" class="com.java.test.HelloWorld"></bean>
     8 
     9   
    10 </beans>
    View Code

    运行结果:

  • 相关阅读:
    pyenv
    [20200724NOIP提高组模拟T3]终章-剑之魂
    [20200724NOIP提高组模拟T2]圣章-精灵使的魔法语
    [20200724NOIP提高组模拟T1]序章-弗兰德的秘密
    [20200723NOIP提高组模拟T1]同余
    [SDOI2008]仪仗队
    P3195 [HNOI2008]玩具装箱
    [20200722NOIP提高组模拟T4]词韵
    [20200721NOIP提高组模拟T3]最小代价
    [20200721NOIP提高组模拟T1]矩阵
  • 原文地址:https://www.cnblogs.com/chenyanlong/p/7493432.html
Copyright © 2011-2022 走看看