第一步:创建一个简单的spring bean

public class HelloWord {private String name;public String getName() {return name;}public void setName(String name) {this.name = name;}
}

第二步:配置spring bean文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:util="http://www.springframework.org/schema/util"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"><!--自己添加的代码--><bean id="helloWord" class="com.spring.beans.HelloWord"><property name="name" value="HelloWord"></property></bean></beans>

第三步:执行代码,获取bean内容

public class SpringTest {public static void main(String[] args) {ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-config.xml");HelloWord helloWord = (HelloWord) applicationContext.getBean(HelloWord.class);System.out.println(helloWord.toString());}
}

输出内容:HelloWord

"C:\Program Files\Java\jdk-10.0.2\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2018.3.2\lib\idea_rt.jar=56713:C:\Program Files\JetBrains\IntelliJ IDEA 2018.3.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\Mr.Liu\IdeaProjects\spring\out\production\spring;C:\Users\Mr.Liu\IdeaProjects\spring\lib\spring-aspects-4.3.18.RELEASE.jar;C:\Users\Mr.Liu\IdeaProjects\spring\lib\spring-context-support-4.3.18.RELEASE.jar;C:\Users\Mr.Liu\IdeaProjects\spring\lib\spring-aop-4.3.18.RELEASE.jar;C:\Users\Mr.Liu\IdeaProjects\spring\lib\spring-expression-4.3.18.RELEASE.jar;C:\Users\Mr.Liu\IdeaProjects\spring\lib\spring-beans-4.3.18.RELEASE.jar;C:\Users\Mr.Liu\IdeaProjects\spring\lib\spring-context-4.3.18.RELEASE.jar;C:\Users\Mr.Liu\IdeaProjects\spring\lib\spring-instrument-4.3.18.RELEASE.jar;C:\Users\Mr.Liu\IdeaProjects\spring\lib\spring-instrument-tomcat-4.3.18.RELEASE.jar;C:\Users\Mr.Liu\IdeaProjects\spring\lib\spring-jdbc-4.3.18.RELEASE.jar;C:\Users\Mr.Liu\IdeaProjects\spring\lib\spring-jms-4.3.18.RELEASE.jar;C:\Users\Mr.Liu\IdeaProjects\spring\lib\spring-oxm-4.3.18.RELEASE.jar;C:\Users\Mr.Liu\IdeaProjects\spring\lib\spring-messaging-4.3.18.RELEASE.jar;C:\Users\Mr.Liu\IdeaProjects\spring\lib\spring-tx-4.3.18.RELEASE.jar;C:\Users\Mr.Liu\IdeaProjects\spring\lib\commons-logging-1.2.jar;C:\Users\Mr.Liu\IdeaProjects\spring\lib\spring-test-4.3.18.RELEASE.jar;C:\Users\Mr.Liu\IdeaProjects\spring\lib\aopalliance-1.0.jar;C:\Users\Mr.Liu\IdeaProjects\spring\lib\spring-core-4.3.18.RELEASE.jar;C:\Users\Mr.Liu\IdeaProjects\spring\lib\spring-orm-4.3.18.RELEASE.jar com.spring.test.SpringTest
3月 17, 2019 10:14:30 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@47ef968d: startup date [Sun Mar 17 22:14:30 CST 2019]; root of context hierarchy
3月 17, 2019 10:14:31 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [spring-config.xml]
HelloWordProcess finished with exit code 0

spring helloWord相关推荐

  1. 1.spring:helloword/注入/CDATA使用/其他Bean/null级联/p命名空间

    新建工程,导入jar,添加spring配置文件(配置文件xxxx.xml)! 1.Helloword实现 Helloword.java public class HelloWord {private ...

  2. SpringBoot2.0使用Spring WebFlux之HelloWord篇

    SpringBoot2.0使用Spring WebFlux之HelloWord篇 Reactive Programming和Reactive Streams 以及 Spring Webflux 介绍 ...

  3. Spring boot的helloword

    目录标题 Spring boot的helloword java代码 Spring boot的helloword 重新学习一次spring boot 顺便做好笔记,不容易忘记. ide 选中file n ...

  4. .jar中没有主清单属性_IDEA中spring boot helloword打包运行-0228-2020

    1.新建maven项目 2.项目构建 3.项目启动 4.打包启动 1.IDEA中新建maven项目 创建项目时选择 Maven,但是不必选择项目骨架, 直接单击 Next 按钮即可 输入组织名称.模块 ...

  5. Spring Boot 专栏:HelloWord快速入门(第一讲)

    写在前面的话: 没有好的文采,但是有一颗乐于分享心,希望用最精简的语言,描绘每一个demo的构建过程,为开发者提供最容易上手的demo样例. SpringBoot简介 Spring Boot来简化Sp ...

  6. 容器类第一个spring项目helloWord

    查了好多资料,发现还是不全,干脆自己整理吧,至少保证在我的做法正确的,以免误导读者,也是给自己做个记录吧! 1.浅谈Spring Spring是一个源开的制控转反(Inversion of Contr ...

  7. Spring MVC 4

    Spring MVC 4 项目文件结构 pom.xml依赖 <properties><endorsed.dir>${project.build.directory}/endor ...

  8. 【spring】第二个springmvc helloworld 以及 spring模糊路径

    第二个helloword 配置文件: 1.添加pom文件 (1)配置parent 代码实现: <parent><groupId>org.springframework.boot ...

  9. Spring中使用Log4j记录日志

    以下内容引用自http://wiki.jikexueyuan.com/project/spring/logging-with-log4j.html: 例子: pom.xml: <project ...

最新文章

  1. 【跃迁之路】【554天】程序员高效学习方法论探索系列(实验阶段311-2018.08.13)...
  2. 你应该知道的 MongoDB 最佳实践
  3. apache常用的配置指令:ServerRoot
  4. android唤醒屏幕并解锁
  5. 如何打开设计思路,避免不断改稿?只需提前做好这一步
  6. Jupyter Notebook 常用的快捷键
  7. Silver Cow Party POJ - 3268(dijkstra+反向交换)
  8. 获取当前日期时间并格式化 - 常见格式
  9. 2019年应届生平均起薪5610元 一线城市吸引力首次跌破30%
  10. c ++结构体构造函数_C ++中的构造函数
  11. android中获取 bitmap 像素的颜色 之吸管取色功能
  12. 小规模45万免税,免的是增值税,没有企业所得税!
  13. 微信公众号基础篇(个人订阅号)
  14. GRUB4DOS(十二)适用于FAT32的分区引导扇区启动代码
  15. go实践二十 web开发--表单唯一token 表单验证 防止xss攻击 上传文件 cookie处理
  16. 国内外dspace著名案例
  17. asp.net网站服务器,vs2010制作简单的asp.net网站
  18. Flask智能图书推荐系统
  19. [算法课]算法考试复习范围全解
  20. jQueryanimation实现漂流瓶扔和写动画效果

热门文章

  1. php码农适合的笔记本,聊一款“码农”比较适合的笔记本
  2. 深度学习深度前馈网络_深度学习前馈网络中的讲义第1部分
  3. 申请邓白氏编码的超详细流程介绍
  4. Thinkphp高仿《拼多多拼团》商城系统源码 可封装APP 完美运营级
  5. TortoiseGit右键无Git Clone
  6. 全新Windows版Checkra1n越狱工具发布,支持iOS12.2~14.8.1
  7. Win RTX3070+cuda11.4+cuDNNv8.2.2+torch-gpu离线安装+tensorflow-gpu安装
  8. 结构方程模型与Mplus软件应用
  9. java获取JTextfield值_[求助]JTextfield 取值问题!
  10. c# autocad二次开发 dwg文件的框表框图导出pdf方便打印 dwg转pdf工具