星空网 > 软件开发 > Java

Spring 一二事(1)

简单介绍一下spring,一方面带新手入入门,一方面自己也重温一下
第一个小工厂先暂时不用maven,下一个会用maven来来配置

jar包只需要一个,spring版本为2.5(暂时为2.5,后续更新,基本核心都是一样的),引入spring.jar到lib,如下:

Spring 一二事(1)

在src下新建applicationContext.

Spring 一二事(1)

内容如下:

<??><beans ="http://www.springframework.org/schema/beans"    ="http://www.w3.org/2001/    ="http://www.springframework.org/schema/context"    xsi:schemaLocation="http://www.springframework.org/schema/beans      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd      http://www.springframework.org/schema/context      http://www.springframework.org/schema/context/spring-context-2.5.xsd">        <!-- 把一个类放入到spring容器中,该类就称为bean -->  <!-- 描述一个类 id 唯一标示 class 类名 -->  <bean id="helloWorld" class="com.lee.spring001.createobject.HelloWorld"></bean></beans>

在com.lee.spring001.createobject包下新建类HelloWorld.java :

package com.lee.spring001.createobject;public class HelloWorld {  public HelloWorld() {    System.out.println("HelloWorld...");  }  /**   *   */  public void hello() {    System.out.println("Hello world!");  }}

测试:

 1 package com.lee.spring001.createobject; 2  3 import org.junit.Test; 4 import org.springframework.context.ApplicationContext; 5 import org.springframework.context.support.ClassPath 6  7 public class HelloWorldTest { 8  9   @Test10   public void testHelloWorld() {11     12     ApplicationContext context = new ClassPath);13     15     HelloWorld hello = (HelloWorld)context.getBean("helloWorld");16     hello.hello();17   }18 }

这样运行junit,成功

 




原标题:Spring 一二事(1)

关键词:Spring

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

今森国际:https://www.goluckyvip.com/tag/34726.html
今森国际 JSEU :https://www.goluckyvip.com/tag/34727.html
今天会发货吗:https://www.goluckyvip.com/tag/34732.html
今天买买:https://www.goluckyvip.com/tag/34733.html
金保通:https://www.goluckyvip.com/tag/34734.html
金保通国际物流:https://www.goluckyvip.com/tag/34735.html
船底顶攻略(船底顶最详细攻略):https://www.vstour.cn/a/411239.html
川藏线自驾游要怎么走才比较划算呢?:https://www.vstour.cn/a/411240.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流