java--Spring5下载与使用入门----1

5 篇文章 0 订阅

一、下载spring5

下载地址:
https://repo.spring.io/ui/native/libs-release-local/org/springframework/spring/5.2.6.RELEASE
在这里插入图片描述
下载解压后:
在这里插入图片描述

二、创建代码工程

1.idea创建普通java工程:
在这里插入图片描述
2.导入spring基础jar包与commons-logging
1)spring基础jar包位置:libs文件夹下
在这里插入图片描述
2)工程目录下新建lib目录,拖入上述5个jar包,并加入依赖
在这里插入图片描述
在这里插入图片描述

三、开始使用spring

1.创建一个类用于测试,必须有无参构造器

package com.my.myClasses;

public class Employee {

    public Employee() {

    }
    
    public void sout(){
        System.out.println("spring test successful!!");
    }
}

2.创建spring配置文件

src目录右键–>new–>XML configuration file–>spring config
在这里插入图片描述
配置文件内容:

<?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="employee" class="com.my.myClasses.Employee"></bean>
</beans>

3.spring测试

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

import com.my.myClasses.Employee;

class SpringTest {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("bean01.xml");

        Employee employee = context.getBean("employee", Employee.class);

        System.out.println(employee);

        employee.sout();
    }
}

执行输出:

com.my.myClasses.Employee@464bee09
spring test successful!!
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维小菜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值