Spring Boot-Logger Aspekte

Ich habe Probleme bekommen meine logging-Aspekt zu Informationen protokollieren, wenn Methoden von Klassen aus einem bestimmten Paket zugegriffen wird. In anderen Worten, "Nein" Protokollierung erfolgt. Ich habe sogar verzweifelt und Hinzugefügt System.aus.println-Anweisungen, mit kein Glück.

Alle meine Klassen befinden sich unter dem org.meine.Paket Paket, d.h. org.meine.Paket.controller, org.meine.Paket.Modell, etc.

Hier ist meine Bewerbung Klasse:

package org.my.package;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

@Configuration
@ComponentScan(basePackages = {"org.my.package.config"})
@EnableAutoConfiguration
@EnableAspectJAutoProxy
public class FirstWebAppApplication {

    public static void main(String[] args) {
        SpringApplication.run(FirstWebAppApplication.class, args);
    }
}

Dies ist meine Konfiguration, Klasse:

package org.my.package.config;

import org.deloitte.javatraining.daythree.utilities.MyLogger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

@Configuration
@EnableAspectJAutoProxy
@ComponentScan(basePackages = {"org.my.package.utilities"})
public class AssetConfig {

    //-----------------------------------------------------------------------------------------------------------------------
    @Bean   
    public MyLogger myLogger(){
       return new MyLogger();
    }
}

Dies ist mein Aspekt-Klasse:

package org.my.package.utilities;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class MyLogger {

    /** Handle to the log file */
    private final Log log = LogFactory.getLog(getClass());

    public MyLogger () {}

    @AfterReturning("execution(* org.my.package.*.*(..))")
    public void logMethodAccessAfter(JoinPoint joinPoint) {
        log.info("***** Completed: " + joinPoint.getSignature().getName() + " *****");
        System.out.println("***** Completed: " + joinPoint.getSignature().getName() + " *****");
    }

    @Before("execution(* org.my.package.*.*(..))")
    public void logMethodAccessBefore(JoinPoint joinPoint) {
        log.info("***** Starting: " + joinPoint.getSignature().getName() + " *****");
        System.out.println("***** Starting: " + joinPoint.getSignature().getName() + " *****");
    }
}

Diese sind meine Gradle build-Abhängigkeiten:

dependencies {
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("org.springframework.boot:spring-boot-starter-web")
    compile('com.h2database:h2:1.3.156')
    compile('javax.servlet:jstl:1.2')
    compile('org.springframework.boot:spring-boot-starter-aop')
    providedRuntime("org.apache.tomcat.embed:tomcat-embed-jasper")
    testCompile("org.springframework.boot:spring-boot-starter-test") 
}

Bin ich etwas fehlt oder anders mis-Konfiguration Aspekt meiner Klasse? Ich kann nicht finden, alles falsch, auch nach überprüfung mit anderen, ähnlich Stack-Overflow-Fragen und online-tutorials.

Bitte beraten.

Sie sind derzeit nur die passenden Methoden auf Klassen in der org.my.package keine sub-packages. Was Sie wahrscheinlich wollen, ist execution( * org.my.package..*.*(..)) beachten Sie die .. statt ..
face-palm Danke!! Das war es dann. Antworten Sie bitte mit einer Antwort, so kann ich geben Sie Kredit für diese Frage.

InformationsquelleAutor Rick | 2015-05-19

Schreibe einen Kommentar