Spring5入门

1.所需jar包:

cormmons-loging

spring-beans
spring-context

spring-core

spirng-expression

 所遇问题:做text测试用到的jar为junit 4.1.12版本  导致报错java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing,,,需要将4.1.12换成4.1.14版本   或者添加jar包hamcrest-core-1.1.jar

2:创建普通类,在这个类创建建普通方法

public class User {
    public void add(){
        System.out.println("add==========");
    }
}

3:创建spring配置文件,在配置文件配置创建的对象

<?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="user" class="com.spring.User"></bean>
</beans>

进行测试代码编写:

@Test
public void testAdd(){
    //加载spring配置文件
    ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
    User user = context.getBean("user", User.class);
    System.out.println(user);
    user.add();
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值