<tbody id="j99e4"></tbody>

<dd id="j99e4"></dd>

  • <button id="j99e4"><object id="j99e4"></object></button>
      1. <th id="j99e4"></th>
        <button id="j99e4"><acronym id="j99e4"></acronym></button><rp id="j99e4"><object id="j99e4"><input id="j99e4"></input></object></rp>

        Spring 初學 - 1. 在基礎java項目中運行Spring
        2022-08-29 23:53:39

        1. 下載并導入必須的包

        需要以下jar包

        1.1 從spring官網下載spring包

        https://repo.spring.io/ui/native/release/org/springframework/spring/

        下載spring-5.2.6.RELEASE-dist.zip,并解壓獲取需要的包

        1.2 下載commons-logging-1.2-bin.zip

        http://commons.apache.org/proper/commons-logging/download_logging.cgi

        下載commons-logging-1.2-bin.zip并解壓出需要的包

        1.3 將包復制到idea中構建的java的基礎項目中

        File -> Project Structure

        ?

        ?

        ?

        2. 創建簡單的類實例并通過Spring進行實例化

        2.1 創建user類文件(user.java)

        package com.firstSpringTest.me;
        
        public class user {
            public void say(){  
                System.out.println("I am a com.firstSpringTest.me.user class");
            }   
        }

        ?

        2.2 構建xml文件(ApplicationContext.xml)

        創建方式:

        ?

        ?添加<bean>

        <?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="user" class="com.firstSpringTest.me.user"></bean>
        </beans>

        2.3 創建測試類(SpringTest.java)

        package com.firstSpringTest.me;
        
        import org.springframework.context.ApplicationContext;
        import org.springframework.context.support.ClassPathXmlApplicationContext;
        
        public class springTest<sout> {
            public static void main(String[] args){
                ApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("ApplicationContext.xml");
                user user = (user) classPathXmlApplicationContext.getBean("user", user.class);
                user.say();
            }
        }

        ?

        運行結果如下

        ?

        本文摘自 :https://www.cnblogs.com/


        更多科技新聞 ......

        亚洲人成图偷偷小说_亚洲图片小说激情综合_国产精品亚洲自在线播放页码_久久综合亚洲色hezyo国产
        <tbody id="j99e4"></tbody>

        <dd id="j99e4"></dd>

      2. <button id="j99e4"><object id="j99e4"></object></button>
          1. <th id="j99e4"></th>
            <button id="j99e4"><acronym id="j99e4"></acronym></button><rp id="j99e4"><object id="j99e4"><input id="j99e4"></input></object></rp>