java null错误事例_java – aspectJ示例中的nullpointer异常
我试图实现我们的stackoverflow成员在这里Logging entry, exit and exceptions for methods in java using aspects给出的建议之一.由于这本身就是不同的问题,再次在这里发布.
我试图搜索,但看起来不同的版本有不同的方式,并无法在网上找出一个例子.我尝试了以下简单示例,因为我是面向方面编程的新手,无法弄清楚如何实现.这个例子是投掷NPE.请帮我理解我做错了什么.
====例外
Exception in thread "main" java.lang.NullPointerException
at aoplogging.SimpleCall.call(SimpleCall.java:13)
at aoplogging.App.main(App.java:18)
正好在SimpleService.simpleCall();
ApplicationContext的:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-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/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">
==================
App.java
package aoplogging;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class App {
public static void main(String[] args) {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml");
SimpleCall call =(SimpleCall) context.getBean("simpleCall");
call.call();
context.close();
}
============ SimpleCall.java
????包aoplogging;
import org.springframework.beans.factory.annotation.Autowired;
public class SimpleCall {
@Autowired
private SimpleService SimpleService;
public void call(){
SimpleService.simpleCall();
try {
SimpleService.processingOperator();
} catch (SMSProcessingException | SMSSystemException e) {
e.printStackTrace();
}
}
}
===== Logging.java
package aoplogging;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class Logging {
@Pointcut("execution(* aoplogging.*.*(..))")
private void selectAll(){}
/**
* This is the method which I would like to execute
* before a selected method execution.
*/
@Before("selectAll()")
public void beforeAdvice(){
System.out.println("Going to setup student profile.");
}
/**
* This is the method which I would like to execute
* after a selected method execution.
*/
@After("selectAll()")
public void afterAdvice(){
System.out.println("Student profile has been setup.");
}
/**
* This is the method which I would like to execute
* when any method returns.
*/
@AfterReturning(pointcut = "selectAll()", returning="retVal")
public void afterReturningAdvice(Object retVal){
System.out.println("Returning:" + retVal.toString() );
}
/**
* This is the method which I would like to execute
* if there is an exception raised by any method.
*/
@AfterThrowing(pointcut = "selectAll()", throwing = "ex")
public void AfterThrowingAdvice(IllegalArgumentException ex){
System.out.println("There has been an exception: " + ex.toString());
}
}
java null错误事例_java – aspectJ示例中的nullpointer异常相关推荐
- java字符串去掉中文_Java——去除字符串中的中文
import java.util.regex.Matcher; import java.util.regex.Pattern; public class RemoveStrChinese { priv ...
- 【Java】错误: 在类 Test1.Test2 中找不到 main 方法, 请将 main 方法定义为: public static void main(String[] args)的解决方案
问题:运行Java程序的时候碰到如下问题 错误: 在类 Test1.Test2 中找不到 main 方法, 请将 main 方法定义为: public static void main(Stri ...
- java null 写前面_java中判断对象为null时,null在前面还是后面
因为目前只学习并使用java语言,所以这里主要是根据java来说的 Java中对null进行判断放在前后没有什么区别,只是为了代码规范,为了避免写代码时书写错误. 下面面两个测试Demo都没有报错.n ...
- java null 对象吗_java中new一个对象和对象=null有什么区别
原创:转载请注明出处 今天在写代码时,遇到一个问题,特此进行记录. for (ProfileDto profileDto : profile) { // Profile resProfile=null ...
- java 跟踪错误程序_Java异常处理 如何跟踪异常的传播路径
当程序中出现异常时,JVM会依据方法调用顺序依次查找有关的错误处理程序. 可使用printStackTrace 和 getMessage方法了解异常发生的情况: printStackTrace:打印方 ...
- java slf4j日志级别_java - 在slf4j中设置运行时消息的日志级别 - 堆栈内存溢出
===============>>#1 票数:41 已采纳 使用slf4j无法做到这slf4j . 我想,缺少这个功能的原因是,几乎不可能为slf4j构建一个Level类型,它可以有效地映 ...
- java语言sql接口_java.sql包中的类和接口及其使用
java.sql包提供使用Java编程语言访问并处理存储在数据源中数据的API,可以动态地安装不同驱动程序来访问不同数据源. 下面,详解java.sql包中包含的常用的接口和类 1.DriverMan ...
- java搜索文本内容_JAVA 搜索文本文件中的关键字
原文链接:http://blog..net/blog_abel/article/details/40858245 用JAVA实现对文本文件中的关键字进行搜索, 依据每一行,得到每一行中出现关键词的个数 ...
- java mongo 日期范围_java – 在mongodb中按日期对值排序
我是mongodb的新手,我正在尝试按日期对所有行进行排序.我有混合来源的记录,我试图分开排序.某些记录在写入db时我没有更新dateCreated.后来我发现并将dateCreated添加到db中的 ...
最新文章
- 数据库事务的悲观锁和乐观锁
- 存在就不插入_动画:面试官问我插入排序和冒泡排序哪个更牛逼?
- 如何为我们的应用程序提供一个更小、更快的视频通话库
- WPF 分页控件应用
- mysql innodb 写锁_MySQL-InnoDB-锁
- Pandas 数据处理三板斧,你会几板?
- redis 辅助工具包 - redis-aux
- [Python] Python 之 __new__() 方法与实例化
- Stata做KHB中介效应分析
- 群晖Docker的高级操作
- 懒人的findviewbyid
- java高校图书馆管理网站计算机毕业设计MyBatis+系统+LW文档+源码+调试部署
- spring test如何设置DebuggingClassWriter.DEBUG_LOCATION_PROPERTY
- (翻译)采用字母间距提高全大写文本可读性的方式
- 数据挖掘系列(1)_Excel的数据挖掘插件安装(SQL Server 2012 office )
- 阿里的面试官都喜欢问哪些问题?
- linux proc目录全称,Linux命令 今天说一说Linux 命令缩写全称
- angular 系列八 ui-router详细介绍及ngRoute工具区别
- 【转】欧姆龙OMRON PLC之 CP1H 以太网FINS/TCP通讯实例
- 【翻】【英汉对照】【完整官方参考】Windows媒体播放器11 SDK 播放器对象模型(三)