Spring框架基本设置案例_helloSpring
来源:互联网 发布:正弦波用stm32怎么编程 编辑:程序博客网 时间:2024/05/20 07:36
1.导包 日志
2.编写applicationContext.xml src下
3.加载配置,创建工程,获得bean
1.导包
2.创建类
HelloSpring.java
package edu.tsinghua.spring;public class HelloSpring { String message="spring DI!"; public void say(){ System.out.println("Hello,"+this.message); } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; }}
Test.java
package edu.tsinghua.spring;import org.springframework.beans.factory.BeanFactory;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Test { public static void main(String[] args) { HelloSpring hs2=new HelloSpring(); System.out.println(hs2); hs2.setMessage("IOC"); hs2.say(); System.out.println("-----------"); //加载配置文件 BeanFactory factory=new ClassPathXmlApplicationContext("applicationContext.xml"); //获得对象 实体 HelloSpring helloSpring=(HelloSpring)factory.getBean("hs"); helloSpring.say(); }}
3.新建、编写配置文件
内容如下:
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans> <bean name="hs" class="edu.tsinghua.spring.HelloSpring" > <property name="message" value="java,你好!"></property> <!-- <property name="message"> <value>NIHAO!</value> </property> --> </bean></beans>
运行后获得如下结果:
Hello,java,你好!
1 0
- Spring框架基本设置案例_helloSpring
- Spring 通知的基本案例
- spring基本框架
- Spring的基本框架
- spring基本框架
- spring mvc 框架图片上传、下载案例
- spring框架搭建与入门案例
- Spring集成Quartz框架的小案例
- Spring框架(基本流程)
- spring基本框架和代码
- Spring框架基本,使用maven
- 01 Spring框架 基本介绍
- spring框架的基本使用
- Spring-Spring框架基本配置文件解析
- springmvc + spring + mybatis 框架设置
- webx中Spring框架的基本流程
- Spring框架学习一----基本配置
- spring框架基本搭建及使用
- leetcode(E) string to integer(atoi)
- 面试问题整理f1
- 启动MyEclipse 报错:java was started but returned exit code = 1
- 支付宝一样的密码验证框
- Matlab中几个数值积分函数的比较和优缺点 【转】
- Spring框架基本设置案例_helloSpring
- 如何在twitter或者github上找靠谱程序员?
- 关于使用aidl中的接口但编译却找不到类的问题
- Http
- android java与webview中js交互
- Jenkins+MAVEN+DUBBO/Tomcat
- php缓存
- windows下程序崩溃,生成dump文件分析
- AFNetworking、ASIHTTPRequest中SSL的使用