Spring开发环境(Java学习笔记)

Spring的目录

Apache Common Logging API 下载地址
Spring 下载地址:

名称作用
docs:包含Spring的API文档和开发规范
libs:包含开发需要的jar包和源码包
schema:包含开发所需要的schema文件,在这些文件中定义了Spring相关配置文件的约束。

libs目录下的4个jar包

名称作用
spring-core-x.x.xx.jar包含Spring框架基本核心工具类,Spring其他组件都要用到这个包中的类,时其他组件的基本核心。
spring-beans-x.x.xx.jar所有应用都要用到的,它包含访问配置文件、创建和管理 Bean 以及进行 Inversion of Control(IoC)或者 Dependency Injection(DI)操作相关的所有类。
spring-context-x.x.xx.jarSpring 提供在基础 IoC 功能上的扩展
spring-expression-x.x.xx.jar定义了 Spring 的表达式语言.需要注意的是,在使用 Spring 开发时,除了 Spring 自带的 JAR 包以外,还需要一个第三方 JAR 包 commons.logging 处理日志信息。

使用 Spring 框架时,只需将 Spring 的 4 个基础包以及 commons-logging-1.2.jar 包复制到项目的 lib 目录,并发布到类路径中即可。

Spring项目的创建

创建Java项目,

在这里插入图片描述
添加jar包
在这里插入图片描述
创建Java类

package org.example;

public class HelloWorld {
    private String message;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}

设置Main.java

package org.example;

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

public class Main {
    public static void main(String[] args) {

        ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
        HelloWorld obj = context.getBean("helloWorld",HelloWorld.class);
        System.out.println(obj.getMessage());

    }

}

创建配置文件

<?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-3.0.xsd">

    <bean id="helloWorld" class="org.example.HelloWorld">
        <property name="message" value="Hello World!" />
    </bean>

</beans>

运行:
在这里插入图片描述

学习文献

文献1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值