//1.建立一个web小程序
//2.导入spring支持
//3.建立一个类
package zyl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class HelloTest {
public String sayHello(String name){
return "Hello"+name;
}
//4.在applicationcontext。xml文件中加入
// <bean id="hello" class="zyl.HelloTest"></bean>
//5.通过程序测试spring的实例化效果
public static void main(String[] args) throws Exception{
ApplicationContext act = new ClassPathXmlApplicationContext("applicationContext.xml");
HelloTest ht = (HelloTest)act.getBean("hello");//spring通过这种方式实例化,效果和反射的类似
System.out.println(ht.sayHello("spring"));
}
}
spring的简单小程序,spring实例化的效果类似于反射
最新推荐文章于 2022-06-07 12:42:19 发布