MyEclipse2017建立Spring項目,

來源:互聯網
上載者:User

MyEclipse2017建立Spring項目,

1、建立一個Web Project

2、右擊項目-->Properties

 

3、搜尋Spring -->Peoject Facets-->在右邊找到Spring,打勾並儲存

 

4、測試

 4.1 建立個類

package cn.spring.user;/*** * @author Dzsom* @date 2018年3月13日下午11:42:03* @encoding UTF-8* @version 1.0   **/public class User {    private String uname;    private int age;    public String getUname() {        return uname;    }    public void setUname(String uname) {        this.uname = uname;    }    public int getAge() {        return age;    }    public void setAge(int age) {        this.age = age;    }    }

  4.2 修改src下的設定檔applicationContext.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"    xmlns:p="http://www.springframework.org/schema/p"    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">    <!-- 將對象交給Spring管理 -->    <bean name="user" class="cn.spring.user.User"></bean></beans>

  4.3 建立測試類別(@Test需要匯入junit包)  

package cn.spring.test;import org.junit.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import cn.spring.user.User;/*** * @author Dzsom* @date 2018年3月14日上午9:35:19* @encoding UTF-8* @version 1.0   **/public class Demo {    @Test    public void fun() {        //1.建立容器物件        ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");        //2.向容器要對象        User user = (User) ac.getBean("user");        //3.列印        System.out.println(user);            }}

 

  4.4 右擊運行測試,若有值輸出則Spring搭建成功

  

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.