要注意spring 版本与jdk的兼容性

applicationContext-resource.xml:

<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.2.xsd
  http://www.springframework.org/schema/tx
  http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
  http://www.springframework.org/schema/aop
  http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
  http://www.springframework.org/schema/context
  http://www.springframework.org/schema/context/spring-context-3.2.xsd ">
  <context:component-scan base-package="com.cdsxt" />
</beans>

base:

public interface BaseDao<T> {}

@Component("baseDao")
public class BaseDaoImpl<T> implements BaseDao<T> {
  private Class clazz;
  public BaseDaoImpl() {
    ParameterizedType type = (ParameterizedType) this.getClass().getGenericSuperclass();
    clazz =(Class) type.getActualTypeArguments()[0];
  }
  public Class getClazz() {
    return clazz;
  }
  public void setClazz(Class clazz) {
    this.clazz = clazz;
  }
}

action:

/**
* @Controller:专门注解 控制层 类
* @Service :专门注解 业务层类
* @Repository:专门注解持久层类
* @Component:可以注解任何类
* @Scope: 控制是否单例
* @Autowired 和 @Resource 都可以注解 被注入的属性
* @author Administrator
*
*/
@Controller
@Scope("prototype")
public class UserAction {
  @Autowired
  private UserService userService;
  public void add(){
    System.out.println("=======UserAction========");
    userService.add();
  }
  public UserService getUserService() {
    return userService;
  }
  public void setUserService(UserService userService) {
    this.userService = userService;
  }
  public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-resource.xml");
    UserAction u1 =(UserAction) context.getBean("userAction");
    u1.add();
  }
}

service:

public interface UserService {
  public void add();
}

@Service("userService")
public class UserServiceImpl implements UserService{
  @Autowired
  private UserDao userDao;
  @Override
  public void add() {
    System.out.println("=========UserServiceImpl============");
    userDao.add();
  }
  public UserDao getUserDao() {
    return userDao;
  }
  public void setUserDao(UserDao userDao) {
    this.userDao = userDao;
  }
}

dao:

public interface UserDao extends BaseDao<User>{
  public void add();
}

@Repository("userDao")
public class UserDaoImpl extends BaseDaoImpl<User> implements UserDao{
  public void add() {
    System.out.println("=========UserDaoImpl==========");
  }
}

po:

public class User {}

spring ioc 注解配置的更多相关文章

  1. Spring IOC的配置使用(转)

    转:http://www.cnblogs.com/linjiqin/p/3408306.html Spring IOC的配置使用 1.1.1 XML配置的结构一般配置文件结构如下: <beans ...

  2. JavaWeb_(Spring框架)注解配置

    系列博文 JavaWeb_(Spring框架)xml配置文件  传送门 JavaWeb_(Spring框架)注解配置 传送门 Spring注解配置 a)导包和约束:基本包.aop包+context约束 ...

  3. java框架之Spring(2)-注解配置IOC&AOP配置

    注解配置IoC 准备 1.要使用注解方式配置 IoC,除了之前引入的基础 jar 包,还需要引入 spring-aop 支持包,如下: 2.在 applicationContext.xml 中引入 c ...

  4. spring IOC注解与xml配置

    转载自:https://blog.csdn.net/u014292162/article/details/52277756 IOC 1小案例 将对象的依赖交给配置文件来配置(配置文件的名字是可以任意的 ...

  5. spring IOC注解方式详解

    本文分为三个部分:概述.使用注解进行属性注入.使用注解进行Bean的自动定义. 一,概述 注释配置相对于 XML 配置具有很多的优势: 它可以充分利用 Java 的反射机制获取类结构信息,这些信息可以 ...

  6. spring aop注解配置

    spring aop是面向切面编程,使用了动态代理的技术,这样可以使业务逻辑的代码不掺入其他乱七八糟的代码 可以在切面上实现合法性校验.权限检验.日志记录... spring aop 用的多的有两种配 ...

  7. Spring的注解配置与XML配置之间的比较

    注释配置相对于 XML 配置具有很多的优势: 它可以充分利用 Java 的反射机制获取类结构信息,这些信息可以有效减少配置的工作. 如:使用 JPA 注释配置 ORM 映射时,我们就不需要指定 PO ...

  8. Spring IOC的配置使用

    1.1.1 XML配置的结构一般配置文件结构如下: <beans> <import resource=”resource1.xml” /> <bean id=”bean1 ...

  9. Spring自定义注解配置切面实现日志记录

    一: spring-mvc.xml: <!--配置日志切面 start,必须与mvc配置在同一个配置文件,否则无法切入Controller层--><!-- 声明自动为spring容器 ...

随机推荐

  1. 搭建openwrt_x86虚拟机环境

    1.下载源码 http://downloads.openwrt.org/snapshots/trunk/x86/openwrt-x86-generic-combined-ext4.img.gz 2.格 ...

  2. 【python】正则表达式-常用函数

    m = re.search(pattern, string) # 搜索整个字符串,直到发现符合的子字符串. m = re.match(pattern, string) # 从头开始检查字符串是否符合正 ...

  3. 关于 eclipse startexplorer插件 快速打开文件夹

    转自:http://basti1302.github.io/startexplorer/ Just drag-and-drop the button to the Eclipse menu bar t ...

  4. [模板] Miller_Rabin素数判断代码实现存档

    就是....存存代码吧. Miller_Rabin的最核心部分在于二次探测定理和费马小定理.后者在同余/逆元的题目里面或多或少都有提及吧.....前者也很简单. 总而言之,Miller_Rabin不算 ...

  5. bzoj1941 Hide and Seek

    Description 小猪iPig在PKU刚上完了无聊的猪性代数课,天资聪慧的iPig被这门对他来说无比简单的课弄得非常寂寞,为了消除寂寞感,他决定和他的好朋友giPi(鸡皮)玩一个更加寂寞的游戏- ...

  6. linux中uptime命令查看linux系统负载

    阅读目录 uptime cat /proc/loadavg 何为系统负载呢? 进阶参考 uptime 另外还有一个参数 -V(大写),是用来查询版本的 [appdeploy@CNSZ22PL0088: ...

  7. wp模版强制用CSS空两格的问题

    之前我写过一篇文章<关于模板该不该用css强制编辑器文本开头空两格>,里面有说到一个观点,模版作者设计的时候,不要控制文章段落空两格,但是我用久了wp,我才慢慢发现,做wp模版的时候,确实 ...

  8. [UE4]C++代码操作SplineMesh

    转自:http://aigo.iteye.com/blog/2279503 void ARaceSpline::OnConstruction(const FTransform& Transfo ...

  9. 【Python量化投资】基于技术分析研究股票市场

    一 金融专业人士以及对金融感兴趣的业余人士感兴趣的一类就是历史价格进行的技术分析.维基百科中定义如下,金融学中,技术分析是通过对过去市场数据(主要是价格和成交量)的研究预测价格方向的证券分析方法. 下 ...

  10. SpringBoot入门篇--热部署

    在项目的开发过程中我们难免会涉及到对代码的修改,有bug我们也需要对代码进行修改,这时候我们就需要重启服务器.但是,我们知道的是这个过程是相当的痛苦的,重启服务器涉及到了所有资源的重新加载,过程那是相 ...