首页 > 其他分享 >Spring入门案例(一)

Spring入门案例(一)

时间:2022-09-18 13:00:09浏览次数:90  
标签:www 入门 Spring springframework 案例 beans userService org UserService

1、导入maven坐标

 <dependency>
    <groupId>org.springframework/groupId>
    <artifactId>spring-context</artifactId>
    <version>5.1.9.RELEASE<version>
</dependency>

2、写个接口类UserService,写个实现类UserServiceImpl  implements  UserService

3、resources文件夹里,添加一个applicationContext.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 https://www.springframework.org/schema/beans/spring-beans.xsd">
    <bean id="userService" class="com.qzerp.service.impl.UserServiceImpl"/>
</beans>

4、新增个UserApp类里面加个main方法调用

ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

UserService userService = (UserService)ctx.getBean("userService");

userService .save();    #调用实现类里的方法

标签:www,入门,Spring,springframework,案例,beans,userService,org,UserService
From: https://www.cnblogs.com/lili520/p/16704628.html

相关文章