zoukankan      html  css  js  c++  java
  • 02、Spring-HelloWorld

    0. 环境准备

    1) jar

      jar包我会帮大家准备好的,所以不用担心找不到Jar包  链接:https://pan.baidu.com/s/1JJcYaspK07JL53vU-q-BUQ 提取码:1028 

    c3p0-0.9.1.2.jar

    commons-logging-1.1.1.jar

    mysql-connector-java-5.1.7-bin.jar

    spring-aop-4.0.0.RELEASE.jar

    spring-beans-4.0.0.RELEASE.jar

    spring-context-4.0.0.RELEASE.jar

    spring-core-4.0.0.RELEASE.jar

    spring-expression-4.0.0.RELEASE.jar

     

    1. applicationContext.xml

     

    1     <!-- 配置bean -->
    2     <bean id="helloworld" class="com.cnblogs.www.pluto.Spring">
    3         <property name="name" value="Spring"></property>
    4     </bean>
    SpringBean

     

    2. HelloWorld.java

     1 public class HelloWorld {
     2 
     3     private String name;
     4 
     5     public void setName(String name) {
     6         System.out.println("setname: "+name);
     7         this.name = name;
     8     }
     9     
    10     public void hello() {
    11         System.out.println("hello "+name);
    12     }
    13 
    14     public HelloWorld() {
    15         System.out.println("helloworld's constructor...");
    16     }
    17     
    18 }
    HelloWorld

    3. Main.java

     1 import org.springframework.context.ApplicationContext;
     2 import org.springframework.context.support.ClassPathXmlApplicationContext;
     3 
     4 public class Main {
     5 
     6     public static void main(String[] args) {
     7         // TODO Auto-generated method stub
     8         /* 
     9         HelloWorld helloWorld = new HelloWorld();
    10         helloWorld.setName("pluto");
    11         helloWorld.hello();
    12         */
    13         
    14         //1.创建Spring的IOC容器对象
    15         ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
    16         //2.从IOC容器中获取Bean实例
    17         HelloWorld helloWorld = (HelloWorld) ctx.getBean("helloworld");
    18         //3.调用hello方法
    19         System.out.println(helloWorld);
    20         helloWorld.hello();
    21     }
    22 
    23 }
    Main

  • 相关阅读:
    Linux内核驱动--硬件访问I/O【原创】
    Linux内核驱动--mmap设备方法【原创】
    Linux系统调用的运行过程【转】
    蓝牙Bluetooth技术手册规范下载【转】
    FarBox--另类有趣的网站服务【转】
    蓝牙HID协议笔记【转】
    linux 串口0x03,0x13的问题【转】
    CC254x/CC2540/CC2541库函数速查(转)
    BLE获取iphone mac地址的方法--【原创】
    用secureCRT操作ubuntu终端
  • 原文地址:https://www.cnblogs.com/HOsystem/p/13022900.html
Copyright © 2011-2022 走看看