spring学习笔记-helloworld
来源:互联网 发布:数据库培训内容 编辑:程序博客网 时间:2024/05/23 18:30
一、建立一个java工程文件,目录如下
lib是我自己建立的,存放我需要的jar包
二、HelloWorld.java
package spring;public class HelloWorld { private String name; public void setName(String name) {this.name = name;} public void hello(){ System.out.println("hello"+name); }}
三、Main.java
package spring;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Main {public static void main(String[] args) {// TODO Auto-generated method stub// 1.创建spring的IOC容器对象 ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationcontext.xml");// 2.从IOC容器中获取bean实例 HelloWorld helloWorld=(HelloWorld)ctx.getBean("helloworld");// 3.调用hello方法 helloWorld.hello();}}四、applicationcontext.xml,注意这个文件是建立在src包下,如果错了,就找不到
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="helloworld" class="spring.HelloWorld"> <property name="name" value="diyunlong"></property> </bean></beans>
运行结果:
阅读全文
0 0
- spring学习笔记-helloworld
- Spring学习笔记之HelloWorld
- 《Spring In Action》学习笔记之HelloWorld
- Spring学习笔记 AOP的HelloWorld
- 学习笔记之Spring入门HelloWorld
- Spring MVC 学习笔记(一):HelloWorld
- Spring框架学习笔记--HelloWorld(二)
- Spring MVC学习笔记(一)---Spring MVC 的HelloWorld
- Spring学习笔记(一) Spring概述和HelloWorld实例
- Spring学习-helloworld
- Spring Boot学习笔记:(一)简介与HelloWorld搭建
- C#学习笔记:HelloWorld
- 《QML HelloWorld》学习笔记
- SpringBoot学习笔记--HelloWorld
- spring学习笔记(1)——创建spring项目之HelloWorld
- (一) Spring Boot学习笔记之第一个Spring Boot程序HelloWorld
- Spring学习(二):Spring的HelloWorld
- Struts 2 学习笔记 - HelloWorld
- Spring配置之C3P0
- jquery-ui输入框自动补全(实用)
- 在虚拟机VMWare下为ubuntu扩展硬盘大小
- openCV---子矩阵赋值
- redis持久化方案
- spring学习笔记-helloworld
- Spring常见面试题总结
- 前端H5初学笔记(二)
- PAT 乙级 1018
- deep learnling概念理解 --Dropout
- you need to have ldconfig in your PATH env when enabling luajit
- 【入门】java基础--3
- Java 8 之 lambda 表达式简单使用入门实例代码。
- java编码规范