J2EE之Eclipse配置Spring插件及Spring建立HelloWord
来源:互联网 发布:淘宝收入排行榜2015 编辑:程序博客网 时间:2024/06/05 20:04
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
- J2EE之Eclipse配置Spring插件及Spring建立HelloWord
- spring-boot 之 helloword
- spring学习之简介helloword
- 标准版eclipse配置J2EE插件,使用maven创建web项目(spring JDBC)
- spring HelloWord
- Eclipse 插件之Spring IDE
- Eclipse插件之Spring IDE
- Eclipse插件之Spring IDE
- Eclipse插件之Spring IDE
- Eclipse插件之Spring IDE
- Eclipse插件之Spring IDE
- Eclipse插件之Spring IDE
- Eclipse插件之Spring IDE
- Eclipse插件之Spring IDE
- Eclipse插件之Spring IDE
- Eclipse安装Spring插件流程及注意事项
- J2EE之Spring简介
- Eclipse插件入门----HelloWord
- 数据库学习之实验二+数据查询
- IO之装饰类ObjectInputStream 、ObjectOutputStream
- IO(一)
- 跟我一起学C++之引用与指针区别
- bzoj 2120 数颜色 (树状数组套主席树)
- J2EE之Eclipse配置Spring插件及Spring建立HelloWord
- java培训至中级结束,写在这里~
- (随笔)位运算和移位运算D
- 静态成员
- 利用filter实现自动登陆
- IO(三)
- make config,make menuconfig,make oldconfig,make xconfig,make defconfig,make gconfig 的简单介绍
- 2016ACM/ICPC亚洲区沈阳站现场赛题解报告
- spring下应用@Resource, @Autowired 和 @Inject注解进行依赖注入的差异