【spring】spring環境搭建、STS工具


 

  • 手動下載jar包的方式

在maven中下載spring的jar包,地址為:http://maven.springframework.org/release/org/springframework/spring/

可以下載spring各個版本的jar包。

以4.3.9示例,下載dist的壓縮包

在解壓縮后需要用到的核心jar包,有

spring-aop.jar (開發AOP特性時需要的JAR),  ...beans(處理Bean的jar), ... context(處理spring上下文的jar),...core(spring核心jar),...expersion(spring表達式)

還需要第三方的commons-logging.jar  https://mvnrepository.com/artifact/commons-logging/commons-logging/1.1.1

 

需要自動提示的時候,需要安裝spring插件 sts

地址 https://spring.io/tools/sts/all 下載對應的版本

或者直接使用官方提供的sts工具 https://spring.io/tools/sts

  • 編寫配置文件

安裝好sts之后,在項目中 新建一個bean configuration  命名叫applicationContext.xml

 在xml文件可以配置bean

以測試Bean Student類來舉例(有三個屬性stuName、stuAge、stuNo)

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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <bean id="student" class="com.beans.Student">
        <property name="stuNo" value="2"></property>
        <property name="stuName" value="ls"></property>
        <property name="stuAge" value="20"></property>
    </bean>

</beans>

測試類:

package com.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.beans.Student;

public class Test {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        Student student = (Student) context.getBean("student");
        System.out.println(student);
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM