J2EE之Eclipse配置Spring插件及Spring建立HelloWord

J2EE之Eclipse配置Spring插件及Spring建立HelloWord

这里写图片描述

这里写图片描述

代码实现:
HelloWord.java:

package com.mooc.spring.beans;

public class HelloWord {
    private String name;



    public void setName(String name) {
        System.out.println("setname:"+name);
        this.name = name;
    }
    public void hello(){
        System.out.println("hello"+name);
    }

    public HelloWord(){
        System.out.println("HelloWord's Constractor....");  
    }

}

main.java:

package com.mooc.spring.beans;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.Locale;
import java.util.Map;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.context.NoSuchMessageException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;

public class main {

    public static void main(String[] args) {
        /*
        //创建HelloWord的一个对象

        HelloWord helloWord=new HelloWord();
        //为那么赋值
        helloWord.setName("atguigu");
        helloWord.hello();

        */

        //1.创建SpringIOC的容器对象
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");

//      2.从IOC容器中获取Bean对象
//      HelloWord helloWord=(HelloWord) context.getBean("helloWord");

        //调用hello方法
//      helloWord.hello();

    }

}

applicationContext.xml:

package com.mooc.spring.beans;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.Locale;
import java.util.Map;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.context.NoSuchMessageException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;

public class main {

    public static void main(String[] args) {
        /*
        //创建HelloWord的一个对象

        HelloWord helloWord=new HelloWord();
        //为那么赋值
        helloWord.setName("atguigu");
        helloWord.hello();

        */

        //1.创建SpringIOC的容器对象
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");

//      2.从IOC容器中获取Bean对象
//      HelloWord helloWord=(HelloWord) context.getBean("helloWord");

        //调用hello方法
//      helloWord.hello();

    }

}

备注:该学习方法和以后学习spring的一些情况,均来自尚硅谷视频教程

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值