[英]Spring AOP not working when running from cmd
我正在Amazon AWS中運行Spring Boot應用程序,並且在調用某些帶注釋的方法時,我正在使用Spring AOP登錄數據庫。
當我使用IntelliJ Idea Ultimate在本地計算機上運行服務器(並且未與gradle任務一起運行!)時,一切工作正常,但是,如果將其部署到ElasticBeans(Java平台)中或與gradle一起運行,則頂部是不工作。 我的功能很好,我看到了結果等。但是我的數據庫中沒有任何記錄。
有人可以幫忙嗎?
@Aspect
@Component
public class JAspects {
private final Aspects aspectWorker;
public JAspects(@Autowired Aspects aspects) {
this.aspectWorker = aspects;
}
@Around(value = "@annotation(enableLogging) && args(reqArg, resArg,..)")
public ResponseEntity around(ProceedingJoinPoint joinPoint, EnableLogging enableLogging, HttpServletRequest reqArg, HttpServletResponse resArg) {
long startTime = System.currentTimeMillis();
ResponseEntity result = null;
try {
result = (ResponseEntity) joinPoint.proceed();
long timeTaken = System.currentTimeMillis() - startTime;
aspectWorker.success(reqArg, resArg, result, timeTaken, enableLogging, joinPoint);
} catch (Throwable throwable) {
long timeTaken = System.currentTimeMillis() - startTime;
aspectWorker.exception(reqArg, resArg, result, timeTaken, enableLogging, joinPoint, throwable);
}
return result;
}}
這就是我使用的方式
@EnableLogging(paramNames = ["firstParam", "secondParam"])
@GetMapping("api/v1/app/{mutation}&{number}/generateRedeem")
fun generateRedeemCodesForWebPage(firstParam:String, secondParam:Int){...}
附加信息
它僅在IntelliJ IDEA中有效。 從命令行運行jar與在aws中運行jar相同(不適用於aop)
這是我的gradle文件
buildscript {
ext {
spekVersion = "1.1.5"
junitVersion = "4.12"
kluentVersion = "1.25"
pegdownVersion = "1.6.0"
kotlinVersion = "1.2.10"
hamkrestVersion = "1.4.2.2"
kotlintestVersion = "2.0.7"
apacheCommonsVersion = "3.7"
mockitoKotlinVersion = "1.5.0"
springBootVersion = "2.0.0.M7"
mysqlConnectorVersion = "6.0.6"
redmineJavaApiVersion = "3.1.0"
junitPlatformVersion = "1.0.2"
mainClass = "hu.click.ServerApplication"
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/libs-snapshot" }
maven { url "http://repo.spring.io/milestone/" }
}
dependencies {
classpath "org.junit.platform:junit-platform-gradle-plugin:$junitPlatformVersion"
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion"
classpath "org.jetbrains.kotlin:kotlin-noarg:$kotlinVersion"
} }
plugins {
id "java"
id "io.spring.dependency-management" version "1.0.3.RELEASE"
id "org.jetbrains.kotlin.jvm" version "1.2.10"
id "org.jetbrains.kotlin.plugin.allopen" version "1.2.10"
id "org.jetbrains.kotlin.plugin.jpa" version "1.2.10"
id "org.jetbrains.kotlin.plugin.noarg" version "1.2.10"
id "org.jetbrains.kotlin.plugin.spring" version "1.2.10"
id "org.jetbrains.kotlin.kapt" version "1.2.10"
id "war"
}
apply plugin: "org.junit.platform.gradle.plugin"
apply plugin: "org.springframework.boot"
springBoot {
mainClass = mainClass
}
noArg {
annotation("hu.click.util.NoArg")
}
kapt {
generateStubs = true
}
junitPlatform {
filters {
engines {
include "spek"
}
}
}
test {
useJUnit {
exclude '**/*IT.class'
}
}
task integrationTest(type: Test) {
useJUnit {
include '**/*IT.class'
}
}
check.dependsOn integrationTest
integrationTest.mustRunAfter test
jar {
baseName = "server"
version = "0.0.1-SNAPSHOT"
manifest {
attributes "Main-Class": mainClass
}
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
maven { url "https://repo.spring.io/libs-snapshot" }
maven { url "http://repo.spring.io/milestone/" }
}
dependencies {
//Spring dependencies
runtime "org.springframework.boot:spring-boot-devtools"
implementation "org.springframework.boot:spring-boot-starter-web"
implementation "org.springframework.boot:spring-boot-starter-mail"
implementation "org.springframework.boot:spring-boot-starter-json"
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
// implementation "org.springframework.boot:spring-boot-starter-actuator"
implementation "org.springframework.boot:spring-boot-starter-aop"
//Kotlin dependencies
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlinVersion"
//Core dependencies
runtime "mysql:mysql-connector-java:$mysqlConnectorVersion"
implementation "org.apache.commons:commons-lang3:$apacheCommonsVersion"
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.2'
// implementation "org.aspectj:aspectjweaver:1.8.8"
// https://mvnrepository.com/artifact/org.aspectj/aspectjrt
// compile group: 'org.aspectj', name: 'aspectjrt', version: '1.8.13'
//App dependencies
implementation "org.pegdown:pegdown:$pegdownVersion"
implementation "com.taskadapter:redmine-java-api:$redmineJavaApiVersion"
//Test dependencies
testCompile "junit:junit:$junitVersion"
testCompile "com.natpryce:hamkrest:$hamkrestVersion"
testCompile "org.amshove.kluent:kluent:$kluentVersion"
testCompile "io.kotlintest:kotlintest:$kotlintestVersion"
testCompile "com.nhaarman:mockito-kotlin:$mockitoKotlinVersion"
testCompile "org.springframework.boot:spring-boot-starter-test"
//these had been excluded to use the supplied kotlin version
testCompile("org.jetbrains.spek:spek-api:$spekVersion") {
exclude group: 'org.jetbrains.kotlin'
}
testRuntime("org.jetbrains.spek:spek-junit-platform-engine:$spekVersion") {
exclude group: 'org.junit.platform'
exclude group: 'org.jetbrains.kotlin'
}
testCompile "org.junit.platform:junit-platform-runner:$junitPlatformVersion"
}
我正在使用gradlew bootJar,bootWar進行包裝
如您所見,我同時使用kotlin和java。 問題是我將Java文件放置在src / main / kotlin目錄中,而不是src / main / java中
一旦我將Java文件復制到正確的目錄,它就開始像魅力一樣工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.