zoukankan      html  css  js  c++  java
  • maven+Spring环境搭建

    一,项目结构图

    二,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:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="
         http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
         http://www.springframework.org/schema/tx
         http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
         http://www.springframework.org/schema/aop
         http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
        <bean id="personDao" class="com.deppon.test04.dao.impl.PersonDao"></bean>
    
        <bean id="personService" class="com.deppon.test04.service.impl.PersonService">
            <property name="personDao" ref="personDao"></property>
        </bean>
    
    </beans>

    三,service

    package com.deppon.test04.service;
    
    public interface IPersonService {
    
        public void processSave();
    }
    package com.deppon.test04.service.impl;
    
    import com.deppon.test04.dao.IPersonDao;
    import com.deppon.test04.service.IPersonService;
    
    public class PersonService implements IPersonService {
        private IPersonDao personDao;
    
        public void setPersonDao(IPersonDao personDao) {
            this.personDao = personDao;
        }
    
        public void processSave() {
            System.out.println("-------------from PersonService.processSave()");
    
            personDao.save();
        }
    
    }

    四,dao

    package com.deppon.test04.dao;
    public interface IPersonDao {
    
        public void save();
    
    }
    package com.deppon.test04.dao.impl;
    
    import com.deppon.test04.dao.IPersonDao;
    
    public class PersonDao implements IPersonDao {
    
        public void save() {
            System.out.println("------------from PersonDao.save()");
        }
    
    }

    五,测试类

    package com.deppon.test04.service;
    
    import org.junit.Before;
    import org.junit.Test;
    import org.springframework.beans.factory.BeanFactory;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class PersonServiceTest {
        private BeanFactory factory = null;
    
        @Before
        public void before() {
            factory = new ClassPathXmlApplicationContext("applicationContext.xml");
        }
    
        @Test
        public void testSpring() {
            IPersonService personService = (IPersonService) factory.getBean("personService");
            personService.processSave();
        }
    }

    转自https://blog.csdn.net/yuguiyang1990/article/details/8799307

  • 相关阅读:
    Eventbus的功能
    Linux下xz与tar的区别
    IntelliJ IDEA出现:This file is indented with tabs instead of 4 spaces的问题解决
    IntelliJ IDEA设置properties文件显示中文
    oh-my-zsh官方教程
    Vim出现:_arguments:450: _vim_files: function definition file not found的问题解决
    Ubuntu 16.04下安装zsh和oh-my-zsh
    zsh与oh-my-zsh是什么
    Mac安装IntelliJ IDEA时快捷键冲突设置
    IntelliJ IDEA删除项目
  • 原文地址:https://www.cnblogs.com/feifeicui/p/8745820.html
Copyright © 2011-2022 走看看