spring入门之环境搭建!!!

1.创建一个maven项目。

不会配置maven环境的可以看这里:maven的下载安装与配置环境变量!!!(全网最详细)_明天更新的博客-CSDN博客

2.引入依赖


        
            org.springframework
            spring-core
            5.2.1.RELEASE
        
        
            org.springframework
            spring-beans
            5.2.1.RELEASE
        
        
            org.springframework
            spring-context
            5.2.1.RELEASE
        
        
            org.springframework
            spring-context-support
            5.2.1.RELEASE
        
    

3.创建一个spring的配置文件

spring入门之环境搭建!!!_第1张图片



    

 4.创建实体类

spring入门之环境搭建!!!_第2张图片

/*
 * Copyright (c) 2020, 2023,  All rights reserved.
 *
 */
package com.entity;

/**
 * 

Project: spring-dome - UserEntity

*

Powered by scl On 2023-09-10 15:43:25

*

描述:

* * @author 孙臣龙 [[email protected]] * @version 1.0 * @since 17 */ public class UserEntity { public void show(){ System.out.println("测试spring环境搭建!!!"); } }

 5.获取Bean对象测试spring环境

spring入门之环境搭建!!!_第3张图片

/*
 * Copyright (c) 2020, 2023,  All rights reserved.
 *
 */

import com.entity.UserEntity;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 

Project: spring-dome - Test01

*

Powered by scl On 2023-09-10 15:47:23

*

描述:

* * @author 孙臣龙 [[email protected]] * @version 1.0 * @since 17 */ public class Test01 { public static void main(String[] args) { ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("spring.xml"); UserEntity userEntity = classPathXmlApplicationContext.getBean("userEntity", UserEntity.class); System.out.println(userEntity); userEntity.show(); } }

 6.测试结果

spring入门之环境搭建!!!_第4张图片

你可能感兴趣的:(spring,java,idea,开发语言)