SSH开发整合中 spring的开发

1· web项目必须的web.xml 文件

首先我们在web.xml文件配置spring的配置文件的位置

<!-- spring配置文件位置 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring.xml,classpath:spring-hibernate.xml</param-value>
    </context-param>

以及配置spring的监听器:

<!-- spring监听器:启动web.xml时启动spring容器 -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


2·然后spring.xml文件也是不可少的

基于注解行的配置所以spring.xml的配置也比较简单

    <!-- 引入属性文件 -->

    <!--因为我是和hiberbate整合的所以在config.properties配置的数据库的username,password等等-->

    <context:property-placeholder location="classpath:config.properties" />

    <!-- 自动扫描dao和service包(自动注入)自动扫描dao,service以及其下面的子包这样就可以使用@service,@comment,@Resp..... -->
    <context:component-scan base-package="sy.dao,sy.service" />

3·然后再进行测试下:

//        ApplicationContext ac = new ClassPathXmlApplicationContext(new String[] { "classpath:spring.xml" });
//        UserServiceI service = (UserServiceI)ac.getBean("userService");
//        service.test();

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值