spring快速开发搭建环境
来源:互联网 发布:淘宝买了双色球送用户 编辑:程序博客网 时间:2024/04/30 09:32
1.加入相关的jar
2.buildpath
3.在src下建立类Hello 有一个属性 Name 有setName(作为一个bean)
new spring bean configuration file --finksh
建立一个bean
package com.my.beans;
public class HelloWord {
private String name;
public void setName1(String name) {
this.name = name;
}
public void Hello(){
System.out.println("hello"+name);
}
}
在应用配置文件中配置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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="hello" class="com.my.jd.Hello"> id bean的标识
<property name="name" value="zhangsan"></property>属性名字和值:就是bean的属性名和给属性赋值value
</bean> class 就是bean的全类名即Hello
</beans>
spring 就是通过class得到类名,用反射创建对象进行赋值
在测试类中写:
package com.my.beans;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main {
public static void main(String[] args) {
// 1.创建spring的IOC对象
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
//2.从IOC中获取bean实例
HelloWord hello = (HelloWord) context.getBean("hello");
//3.调用hello方法
hello.Hello();
}
}
注意:classpath:是src下
- spring快速开发搭建环境
- 快速搭建Spring MVC 4开发环境
- 快速搭建Spring MVC 4开发环境 .
- 快速搭建Spring MVC 4开发环境
- 快速搭建Spring+Mybatis开发环境
- 3分钟快速搭建Spring Boot开发环境
- 搭建Spring开发环境
- 搭建spring开发环境
- 搭建Spring开发环境
- Spring开发环境搭建
- 快速搭建Android开发环境
- 快速搭建php开发环境
- 快速搭建python开发环境
- 快速搭建linux开发环境
- Python开发环境快速搭建
- 【OpenWRT】快速搭建开发环境
- ES6开发环境快速搭建
- 快速搭建AMP开发环境
- sa5ssd74sg39
- java实现一个在窗口显示一个随机生成的号码
- qemu-kvm 设备虚拟化----I/O 端口和 I/O 内存
- dsad235sag32423
- UI开发----UIController及其子类
- spring快速开发搭建环境
- org.apache.subversion.javahl.ClientException: Attempted to lock an already-locked dir
- ssdgdf534sg
- rhel6语言设置
- dshfhuiwreyywe
- Paint it!
- C++静态成员变量
- C二维数组练习
- POJ 2591 解题报告