J2EE之Eclipse配置Spring插件及Spring建立HelloWord
2016-10-30 17:17
253 查看
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的一些情况,均来自尚硅谷视频教程
相关文章推荐
- 标准版eclipse配置J2EE插件,使用maven创建web项目(spring JDBC)
- eclipse(xmlbuddy插件)为xml文件自动提示(同MyEclipse编辑XML的提示功能),以spring配置文件为例
- Eclipse插件系列:spring插件配置
- Win7下J2EE Eclipse中Tomcat和SVN插件配置
- Eclipse建立一个spring的HelloWord
- Maven 配置tomcat和findbug插件(在eclipse建立的项目中)
- Eclipse安装spring配置文件提示插件
- 解决eclipse中配置maven插件,因为网速慢而不能建立maven工程的问题
- 在eclipse + MyEclipse下配置建立J2EE工程
- Maven 配置tomcat和findbug插件(在eclipse建立的项目中)
- eclipse安装spring tool suite插件便于xml配置文件选择命名空间添加
- 【Java】Eclipse中Spring插件配置
- 在eclipse + MyEclipse下配置建立J2EE工程- -
- 在eclipse中配置spring插件
- Maven+SpringMVC+Eclipse软件安装配置,Maven报插件异常,Eclipse总是卡死的解决方法,导入一个maven工程后 一直显示importing maven project
- 在eclipse + MyEclipse下配置建立J2EE工程
- eclipse上配置spring 插件-zt
- 在eclipse + MyEclipse下配置建立J2EE工程
- Eclipse安装了SpringSource Tool Suite插件后,编辑SpringBoot项目的yml配置文件仍然没有提示信息的解决办法
- 配置Bytecode Outline插件-eclipse插件