日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java null错误事例_java – aspectJ示例中的nullpointer异常

發布時間:2023/12/10 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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异常的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。