WEB开发网
开发学院软件开发Java S2SH框架配置步骤 阅读

S2SH框架配置步骤

 2009-09-24 00:00:00 来源:WEB开发网   
核心提示: SpringTest.java:1packagetest.spring;23importorg.springframework.context.ApplicationContext;4importorg.springframework.context.support.ClassPathXmlAp

SpringTest.java:

 1package test.spring;
 2
 3import org.springframework.context.ApplicationContext;
 4import org.springframework.context.support.ClassPathXmlApplicationContext;
 5
 6public class SpringTest {
 7    public static void main( String[] args ) {
 8        //加载spring配置文件,初始化IoC容器
 9        ApplicationContext ac = new ClassPathXmlApplicationContext("spring/applicationContext.xml");
10        //从容器 接管Bean
11        TUser user = (TUser) ac.getBean("TUser");
12        //输出欢迎信息
13        System.out.println( "Hello:" + user.getUsername() + ";u is in " + user.getAddress() + " ; and u is  " + user.getAllname() );
14    }
15}
16

创建完毕后,就剩最后一步了,在applicationContext.xml中配置一个bean,在xml中增加如下代码:

<bean id="TUser" class="test.spring.TUser">
        <property name="username" value="小张"></property>
        <property name="allname" value="张三"></property>
        <property name="address" value="青岛市"></property>
    </bean>

好了,下面运行一下吧,右键单击SpringTest.java选择run as àJava Application,运行结果如下:

上一页  3 4 5 6 7 8 9 10  下一页

Tags:SSH 框架 配置

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接