文档开发者中心
我的

史上最详细的IDEA优雅整合Maven+SSM框架(详细思路+附带源码)【中篇】


2、编写applicationContext.xml的配置文件

在resources资源文件中创建applicationContext.xml的配置文件,编写具体的配置信息
在这里插入图片描述
在这里插入图片描述
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'
       xmlns:context='http://www.springframework.org/schema/context'
       xmlns:aop='http://www.springframework.org/schema/aop'
       xmlns:tx='http://www.springframework.org/schema/tx'
       xsi:schemaLocation='http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context.xsd
 http://www.springframework.org/schema/aop
 http://www.springframework.org/schema/aop/spring-aop.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx.xsd'>

    <!--开启注解的扫描,希望处理service和dao,controller不需要Spring框架去处理-->
    <context:component-scan base-package='com.gx' >
        <!--配置哪些注解不扫描-->
        <context:exclude-filter type='annotation' expression='org.springframework.stereotype.Controller' />
    </context:component-scan>
    </beans>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

3. 在项目中编写测试方法,进行测试

1、创建Test包
在这里插入图片描述
在这里插入图片描述
2、在test包中创建一个叫TestSpring的class类,具体的内容如下:

package com.gx.test;import com.gx.domain.Account;import com.gx.service.AccountService;import org.junit.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class TestSpring {
    @Test
    public void run1(){
        ApplicationContext ac = new ClassPathXmlApplicationContext('classpath:applicationContext.xml');
        AccountService as = (AccountService) ac.getBean('accountService');
        as.findAll();
    }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

运行如下效果,说明搭建Spring的开发环境成功!
在这里插入图片描述
到这里,Spring的开发环境成功!接下来搭建SpringMVC框架环境。

点赞
收藏
回复
分享
举报
浏览349 发布于2019-11-14 14:34未知归属地
全部评论
最多点赞
最新发布
最早发布
暂无评论
暂无评论
写回答
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
  • 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
  • 如您发布的内容为转载内容,请注明内容来源。

我要发帖子

了解社区公约,与您携手共创和谐专业的开发者社区。