首页 > 编程语言 > 详细

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

时间:2019-07-23 13:21:36      阅读:93      评论:0      收藏:0      [点我收藏+]

 

  • 手动下载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);
    }
}

 

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

原文:https://www.cnblogs.com/to-red/p/11231090.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!