看《Spring in action》有一段时间了,陆续也都看懂了,但是看懂和自己动手写确实是两回事,今天花了几个小时陆续开始安装spring,开始使用DI,然后使用AOP,在写AOP例子代码的过程中遇到一个编译错误,调试了很久,最终找到愿意了,少加了一个jar包,在pom文件中添加之后就ok了。

 package com.DbInterface.config;

 public interface SetupTable {
public int readSetupNodeByNodeTypeId(int nodeType, int nodeId, boolean includeChild);
public int readAllNodes();
public int writeNode(int nodeType, int nodeId, String nodeName);
public int deleteNode(int nodeType, int nodeId);
}
package com.DbInterface;

import com.DbInterface.config.*;

public class DbInterface {
public SetupTable getSetupTable() {
return setupTable;
}
public void setSetupTable(SetupTable setupTable) {
this.setupTable = setupTable;
}
public RealtimeTable getRealtimeTable() {
return realtimeTable;
}
public void setRealtimeTable(RealtimeTable realtimeTable) {
this.realtimeTable = realtimeTable;
}
public CommandTable getCommandTable() {
return commandTable;
}
public void setCommandTable(CommandTable commandTable) {
this.commandTable = commandTable;
} private SetupTable setupTable;
private RealtimeTable realtimeTable;
private CommandTable commandTable;
}
package com.DbInterfaceForPG;

import com.DbInterface.config.SetupTable;

public class SetupTableForPG implements SetupTable {

    public int readSetupNodeByNodeTypeId(int nodeType, int nodeId, boolean includeChild) {
System.out.println(String.format("readSetupNodeByNodeTypeId, nodeType=%d, nodeId=%d, includeChild=%b", nodeType, nodeId, includeChild));
return 0;
} public int readAllNodes(){
System.out.println("readAllNodes");
return 0;
}
public int writeNode(int nodeType, int nodeId, String nodeName) {
System.out.println(String.format("writeNode, nodeType=%d, nodeId=%d, nodeName=%s", nodeType, nodeId, nodeName));
return 0;
} public int deleteNode(int nodeType, int nodeId) {
System.out.println(String.format("deleteNode, nodeType=%d, nodeId=%d", nodeType, nodeId));
return 0;
} }
<?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:c="http://www.springframework.org/schema/c"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd"> <aop:config>
<aop:aspect ref="logger">
<aop:pointcut id="dbmethod" expression="execution(* com.DbInterfaceForPG.SetupTableForPG.*(..))" />
<aop:before pointcut-ref="dbmethod" method="logBefore" />
<aop:after pointcut-ref="dbmethod" method="logAfter" />
</aop:aspect>
</aop:config> <bean id="dbInterface" class="com.DbInterface.DbInterface" autowire="byType"/>
<bean id="setupTable" class="com.DbInterfaceForPG.SetupTableForPG"/>
<bean id="logger" class="com.PecTrend.util.LoggerWithMethodName"/>
</beans>
public class App
{
public static void main( String[] args )
{
ApplicationContext ctx = new ClassPathXmlApplicationContext("PecTrend.xml");
DbInterface dbInterface = (DbInterface)ctx.getBean("dbInterface");
if(dbInterface.getSetupTable() != null)
dbInterface.getSetupTable().readSetupNodeByNodeTypeId(123, 456, false);
else
System.out.println("装配 setupTable 失败");
}
}

Java系列: 我的第一个spring aop练习的更多相关文章

  1. 框架源码系列三:手写Spring AOP(AOP分析、AOP概念学习、切面实现、织入实现)

    一.AOP分析 问题1:AOP是什么? Aspect Oriented Programming 面向切面编程,在不改变类的代码的情况下,对类方法进行功能增强. 问题2:我们需要做什么? 在我们的框架中 ...

  2. Spring系列(四):Spring AOP详解

    一.AOP是什么 AOP(面向切面编程),可以说是一种编程思想,其中的Spring AOP和AspectJ都是现实了这种编程思想.相对OOP(面向过程编程)来说,提供了另外一种编程方式,对于OOP过程 ...

  3. Java缓存框架使用EhCache结合Spring AOP

    一.Ehcache简介     EhCache是一个纯Java的进程内缓存框架,具有如下特点:     1. 快速简单,非常容易和应用集成.     2.支持多种缓存策略 .     3. 缓存数据有 ...

  4. Spring系列(五):Spring AOP源码解析

    一.@EnableAspectJAutoProxy注解 在主配置类中添加@EnableAspectJAutoProxy注解,开启aop支持,那么@EnableAspectJAutoProxy到底做了什 ...

  5. 使用IDEA搭建一个Spring + AOP (权限管理 ) + Spring MVC + Mybatis的Web项目 (零配置文件)

    前言: 除了mybatis 不是零配置,有些还是有xml的配置文件在里面的. 注解是Spring的一个构建的一个重要手段,减少写配置文件,下面解释一下一些要用到的注解: @Configuration  ...

  6. Spring AOP 系列总括

    Spring有两大核心,IOC和AOP.IOC在Java Web项目中无时无刻不在使用,然而AOP用的比较少,尤其是对一些初级程序员,在架构师搭好的框架上开发应用代码,AOP几乎是透明的.然而,项目中 ...

  7. Spring系列(四):Spring AOP详解和实现方式(xml配置和注解配置)

    参考文章:http://www.cnblogs.com/hongwz/p/5764917.html 一.什么是AOP AOP(Aspect Oriented Programming),即面向切面编程, ...

  8. 【转】Java Spring AOP详解

    一.前言 在以前的项目中,很少去关注spring aop的具体实现与理论,只是简单了解了一下什么是aop具体怎么用,看到了一篇博文写得还不错,就转载来学习一下,博文地址:http://www.cnbl ...

  9. Spring系列(六):Spring事务源码解析

    一.事务概述 1.1 什么是事务 事务是一组原子性的SQL查询,或者说是一个独立的工作单元.要么全部执行,要么全部不执行. 1.2 事务的特性(ACID) ①原子性(atomicity) 一个事务必须 ...

随机推荐

  1. js地理位置获取、显示、轨迹绘制

    JS新API标准 地理定位(navigator.geolocation) 基于 html5 geolocation来获取经纬度地址 Html5 Geolocation获取地理位置信息 HTML5获取地 ...

  2. C++中const用法总结

    1修饰变量/指针 注意以下几种修饰的区别: (1)const int * a; (2)int const *a; (3)int * const b; (4)int const* const c; 其中 ...

  3. 超酷的测速网站Ookla SPEEDTEST

    测试网速的工具.网站估计不少,在百度一搜都能搜出一大堆,下面介绍一个国外测试网速的网站,用户体验相当棒,感觉酷毙了,那些其它测试网速的网站跟这个比起来,简直弱毙了.这个网速测试网站就是:http:// ...

  4. 网站的SEO

    提高网站SEO排名的策略除了要有高质量的内容,还有几种方案可以使用 1.关键词的设定 合适的关键词可以提升搜索引擎中的排名 ①最重要的是html中的title标签,这也是一个页面的最重要的概括,所以尽 ...

  5. openstack-networking-neutron(四)--iptables

    Filter表:过滤数据包,默认表. (1)INPUT   链:过滤所有目标地址是本机的数据包(对进入本机数据包的过滤) (2)OUTPUT 链:过滤所有本机产生的数据包(对源地址得数据包的过滤) ( ...

  6. jsp EL 表达式

    EL表达式 EL 全名为Expression Language EL 语法很简单,它最大的特点就是使用上很方便.接下来介绍EL主要的语法结构: ${sessionScope.user.sex} 所有E ...

  7. POJ 2513 Colored Sticks(欧拉回路,字典树,并查集)

    题意:给定一些木棒,木棒两端都涂上颜色,求是否能将木棒首尾相接,连成一条直线,要求不同木棒相接的一边必须是相同颜色的.   无向图存在欧拉路的充要条件为: ①     图是连通的: ②     所有节 ...

  8. [部署]CentOS安装apache

    环境 虚拟机:VMWare10.0.1 build-1379776 操作系统:CentOS7 64位 步骤 1.使用yum安装 yum install httpd httpd-devel 2.启动 a ...

  9. 【学习/研发】嵌入式Linux/Android开发有它就够了——迅为4412开发板

    网站:http://www.topeetboard.com 光盘资料+网盘资料+配套视频+售后支持,助您加速学习研发的进程 产品介绍 iTOP-Exynos4412开发板采用 Exynos4412的主 ...

  10. MyDiary,《你的名字。》同款日记应用

    新海城导演的新作<你的名字.>已经于 12 月 2 日在国内公映,这部评价极高的动画电影无论在剧情还是美术上都相当出色,是一部不容错过的好片.如果你还没有看过,赶快趁着还没下档买票去看看吧 ...