我的第一个spring程序

来源:互联网 发布:java 新浪短网址生成 编辑:程序博客网 时间:2024/05/30 22:42

1.新建一个demo1实体类,代码如下:

package com.eduask.entity;

//新建一个学生实体类;

public class Demo1 {

public Demo1(){

System.out.println("我的第一个spring程序");

}

}

2.新建一个TestDemo1测试类代码如下:

package com.eduask.entity;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestDemo1 {

public static void main(String[] args) {

ClassPathXmlApplicationContext cx=new ClassPathXmlApplicationContext("demo1.xml");

Demo1 demo1=(Demo1) cx.getBean("Demo1");

}

}

3.新建一个demo1.xml配置文件,

<?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="Demo1" class="com.eduask.entity.Demo1">

</bean>

</beans>

0 0