zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然轻量级JAVA EE企业应用开发Struts2Sping4Hibernate整合开发学习笔记:Spring_Autowired

    <?xml version="1.0" encoding="GBK"?>
    <project name="spring" basedir="." default="">
        <property name="src" value="src"/>
        <property name="dest" value="classes"/>
    
        <path id="classpath">
            <fileset dir="../../lib">
                <include name="**/*.jar"/>
            </fileset>
            <pathelement path="${dest}"/>
        </path>
    
        <target name="compile" description="Compile all source code">
            <delete dir="${dest}"/>
            <mkdir dir="${dest}"/>
            <copy todir="${dest}">
                <fileset dir="${src}">
                    <exclude name="**/*.java"/>
                </fileset>        
            </copy>
            <javac destdir="${dest}" debug="true" includeantruntime="yes"
                deprecation="false" optimize="false" failonerror="true">
                <src path="${src}"/>
                <classpath refid="classpath"/>
                <compilerarg value="-Xlint:deprecation"/>
            </javac>
        </target>
    
        <target name="run" description="Run the main class" depends="compile">
            <java classname="lee.BeanTest" fork="yes" failonerror="true">
                <classpath refid="classpath"/>
            </java>
        </target>
    
    </project>
    <?xml version="1.0" encoding="GBK"?>
    <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"
        xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.0.xsd">
        <context:component-scan
            base-package="org.crazyit.app.service,org.crazyit.app.dao"/>     
    </beans>
    package lee;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    import org.crazyit.app.service.*;
    import org.crazyit.app.domain.*;
    /**
     * Description:
     * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
     * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author  Yeeku.H.Lee kongyeeku@163.com
     * @version  1.0
     */
    public class BeanTest
    {
        public static void main(String[] args)throws Exception
        {
            // 创建Spring容器
            ApplicationContext ctx = new
                ClassPathXmlApplicationContext("beans.xml");
            UserService us = ctx.getBean("userService", UserService.class);
            us.addEntity(new User());
            ItemService is = ctx.getBean("itemService", ItemService.class);
            is.addEntity(new Item());
        }
    }
    package org.crazyit.app.dao;
    
    /**
     * Description:
     * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
     * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author Yeeku.H.Lee kongyeeku@163.com
     * @version 1.0
     */
    public interface BaseDao<T>
    {
        void save(T e);
    }
    package org.crazyit.app.dao;
    
    import org.crazyit.app.domain.*;
    /**
     * Description:
     * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
     * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author Yeeku.H.Lee kongyeeku@163.com
     * @version 1.0
     */
    public interface ItemDao extends BaseDao<Item>
    {
    }
    package org.crazyit.app.dao;
    
    import org.crazyit.app.domain.*;
    /**
     * Description:
     * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
     * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author Yeeku.H.Lee kongyeeku@163.com
     * @version 1.0
     */
    public interface UserDao extends BaseDao<User>
    {
    }
    package org.crazyit.app.dao.impl;
    
    import org.crazyit.app.dao.*;
    /**
     * Description:
     * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
     * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author Yeeku.H.Lee kongyeeku@163.com
     * @version 1.0
     */
    public class BaseDaoImpl<T> implements BaseDao<T>
    {
        public void save(T e)
        {
            System.out.println("程序保存对象:" + e);
        }
    }
    package org.crazyit.app.dao.impl;
    
    import org.springframework.stereotype.*;
    
    import org.crazyit.app.dao.*;
    import org.crazyit.app.domain.*;
    /**
     * Description:
     * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
     * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author Yeeku.H.Lee kongyeeku@163.com
     * @version 1.0
     */
    @Component("itemDao")
    public class ItemDaoImpl extends BaseDaoImpl<Item>
        implements ItemDao
    {
    }
    package org.crazyit.app.dao.impl;
    
    import org.springframework.stereotype.*;
    
    import org.crazyit.app.dao.*;
    import org.crazyit.app.domain.*;
    /**
     * Description:
     * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
     * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author Yeeku.H.Lee kongyeeku@163.com
     * @version 1.0
     */
    @Component("userDao")
    public class UserDaoImpl extends BaseDaoImpl<User>
        implements UserDao
    {
    }
    package org.crazyit.app.domain;
    
    /**
     * Description:
     * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
     * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author Yeeku.H.Lee kongyeeku@163.com
     * @version 1.0
     */
    public class Item
    {
    }
    package org.crazyit.app.domain;
    
    /**
     * Description:
     * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
     * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author Yeeku.H.Lee kongyeeku@163.com
     * @version 1.0
     */
    public class User
    {
    }
    package org.crazyit.app.service;
    
    import org.springframework.stereotype.*;
    import org.springframework.beans.factory.annotation.*;
    
    import org.crazyit.app.service.*;
    
    /**
     * Description:
     * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
     * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author  Yeeku.H.Lee kongyeeku@163.com
     * @version  1.0
     */
    public interface BaseService<T>
    {
        void addEntity(T entity);
    }
    package org.crazyit.app.service;
    
    import org.springframework.stereotype.*;
    import org.springframework.beans.factory.annotation.*;
    
    import org.crazyit.app.service.*;
    import org.crazyit.app.domain.*;
    /**
     * Description:
     * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
     * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author  Yeeku.H.Lee kongyeeku@163.com
     * @version  1.0
     */
    @Component
    public interface ItemService extends BaseService<Item>
    {
    
    }
    package org.crazyit.app.service;
    
    import org.springframework.stereotype.*;
    import org.springframework.beans.factory.annotation.*;
    
    import org.crazyit.app.service.*;
    import org.crazyit.app.domain.*;
    /**
     * Description:
     * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
     * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author  Yeeku.H.Lee kongyeeku@163.com
     * @version  1.0
     */
    @Component
    public interface UserService extends BaseService<User>
    {
    }
    package org.crazyit.app.service.impl;
    
    import org.springframework.stereotype.*;
    import org.springframework.beans.factory.annotation.*;
    
    import org.crazyit.app.dao.*;
    import org.crazyit.app.service.*;
    /**
     * Description:
     * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
     * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author  Yeeku.H.Lee kongyeeku@163.com
     * @version  1.0
     */
    public class BaseServiceImpl<T> implements BaseService<T>
    {
        @Autowired
        private BaseDao<T> dao;
        public void addEntity(T entity)
        {
            System.out.println("调用" + dao
                + "保存实体:" + entity);
        }
    }
    package org.crazyit.app.service.impl;
    
    import org.springframework.stereotype.*;
    import org.springframework.beans.factory.annotation.*;
    
    import org.crazyit.app.service.*;
    import org.crazyit.app.domain.*;
    
    /**
     * Description:
     * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
     * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author  Yeeku.H.Lee kongyeeku@163.com
     * @version  1.0
     */
    @Component("itemService")
    public class ItemServiceImpl extends BaseServiceImpl<Item>
        implements ItemService
    {
    }
    package org.crazyit.app.service.impl;
    
    import org.springframework.stereotype.*;
    import org.springframework.beans.factory.annotation.*;
    
    import org.crazyit.app.service.*;
    import org.crazyit.app.domain.*;
    /**
     * Description:
     * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
     * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author  Yeeku.H.Lee kongyeeku@163.com
     * @version  1.0
     */
    @Component("userService")
    public class UserServiceImpl extends BaseServiceImpl<User>
        implements UserService
    {
    }
  • 相关阅读:
    VS2008编译出现问题:error C2485: “__restrict”: 无法识别的扩展属性 解决办法
    精度试验结果报告Sleep, GetTickCount, timeGetTime, QueryPerformanceCounter
    error C2872: 'ULONG_PTR' : ambiguous symbol
    无法删除文件:无法读源文件或磁盘”
    如何HOOK桌面窗口消息
    批处理常用特殊符号
    我的Hook学习笔记
    代码注入的三种方法
    Ubuntu 安装 “宋体,微软雅黑,WPS Office的symbol、wingdings、wingdings 2、wingdings 3、webding字体,Consolas雅黑混合版编程字体” 等 Windows 7 下的字体(转)
    Delphi中如何将 Exe 程序或其他资料打包在内,使用时再释放使用(转)
  • 原文地址:https://www.cnblogs.com/tszr/p/12372104.html
Copyright © 2011-2022 走看看