<p id="g32nn"></p>
    1. <acronym id="g32nn"><strong id="g32nn"></strong></acronym>
      <pre id="g32nn"></pre>

      <table id="g32nn"><option id="g32nn"></option></table>
          當前位置:首頁 > IT技術 > 編程語言 > 正文

          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/

          97久久久久人妻精品专区_国产成人精品视频导航_国产色诱视频在线播放网站_97午夜理论电影影院
          <p id="g32nn"></p>
          1. <acronym id="g32nn"><strong id="g32nn"></strong></acronym>
            <pre id="g32nn"></pre>

            <table id="g32nn"><option id="g32nn"></option></table>