从cmd运行时,Spring AOP不工作
我正在亚马逊aws运行一个Spring启动应用程序,并且我正在使用Spring AOP登录到一个数据库,当一些注释的方法被调用。
当我使用IntelliJ Idea Ultimate(而不是使用gradle任务运行)在本地计算机上运行我的服务器时,一切正常,但是,如果将其部署到ElasticBeans(Java平台)或使用Gradle运行,则顶部是不工作。 我的function很好,我看到的结果等..但没有记录在我的数据库。
有人可以帮忙吗?
@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(不工作)是一样的,
这是我的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文件到正确的目录,它开始像魅力工作。
- Gradle不会导入bintray依赖项,但不会引发任何错误
- Android的gradle无法find方法’org.grade.api.internal.file.DefaultSourceDirectorySet’
- 无法得到类型为…的对象的未知属性“anko_version”?
- 我如何从Gradle中运行Kotlin-Script(* .kts)filles?
- 与Gradle不兼容的ClassChangeError
- 在一个Android项目中,Jacoco报告了Kotlin类的unit testing覆盖率
- kotlin-kapt插件不使用“kapt.generateStubs”
- 如何运行./gradlew测试
- 在Kotlin脚本中用扩展方法问题