我有一个使用自编库的服务。在库中,我使用了一些 Spring 功能并扩展了一个 bean 后处理器以允许一些自定义配置。lib 本身包含 Spring 库作为 gradle 下的编译依赖项。这一切看起来如下:
构建.gradle
buildscript {
ext {
springBootVersion = '2.0.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'org.stuff.library'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
ext {
springCloudVersion = 'Finchley.RELEASE'
jacksonVersion = '2.9.6'
lombokVersion = '1.16.18'
jooqVersion = '3.11.2'
flywayVersion = '5.1.3'
}
dependencies {
compile 'org.aspectj:aspectjweaver'
compile 'org.springframework:spring-tx'
compile 'org.springframework.cloud:spring-cloud-stream'
compile 'org.springframework.cloud:spring-cloud-stream-binder-kafka'
compile 'org.apache.commons:commons-lang3:3.5'
compile 'org.javassist:javassist:3.22.0-GA'
compile "org.flywaydb:flyway-core:${flywayVersion}"
compileOnly "org.jooq:jooq:${jooqVersion}"
compileOnly "org.projectlombok:lombok:${lombokVersion}"
// other testCompile dependencies
}
Bean 扩展后处理器:
package org.stuff.library.config;
public class AnnotationTypePostProcessor extends AnnotationTypeBeanPostProcessor {
@Override
public AnnotationType postProcessAnnotation(AnnotationType original Annotation, Method annotatedMethod) {
... do some service-specific stuff
return super.postProcessAnnotation();
}
}
启动时,我发出一个组件扫描,通过org.stuff它是我的服务和我的库的父包。
如果我包含.jar自己库的文件,则库配置中的 bean未初始化,尽管配置本身已初始化。
为什么会发生这种情况?我使用或不使用源扫描相同的包,并且它本身期望带来的唯一库与 Spring 无关。
BIG阳
相关分类