Spring Boot Webflux应用程序重新启动并导致重复的EnhancerBySpringCGLIB

我有一个Webflux应用,它在使用几分钟后会自动重新启动,sometimes I can use it for a couple of hours然后突然重新启动,当它重新启动时弹出错误提示重复EnhancerBySpringCGLIB。我知道之前曾有人问过这个问题,因此我尝试了建议的解决方案,但没有一个起作用。下面是我的日志

2020-07-26 10:18:00.515  INFO 23080 --- [  restartedMain] u.s.w.NcitoAfricaApplication             : Started NcitoAfricaApplication in 5.37 seconds (JVM running for 6.719)
2020-07-26 10:18:00.523 DEBUG 23080 --- [  restartedMain] o.s.b.d.r.Restarter                      : Creating new Restarter for thread Thread[main,5,main]
2020-07-26 10:18:00.523 DEBUG 23080 --- [  restartedMain] o.s.b.d.r.Restarter                      : Immediately restarting application
2020-07-26 10:18:00.523 DEBUG 23080 --- [  restartedMain] o.s.b.d.r.Restarter                      : Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@1cbd5ea1
2020-07-26 10:18:00.523 DEBUG 23080 --- [  restartedMain] o.s.b.d.r.Restarter                      : Starting application ubuntu.software.web.NcitoAfricaApplication with URLs [file:/C:/Users/alungu5/IdeaProjects/Tubombeko/]
2020-07-26 10:30:15.181 DEBUG 23080 --- [   File Watcher] o.s.b.d.r.Restarter                      : Restarting application
2020-07-26 10:30:15.185 DEBUG 23080 --- [     Thread-385] o.s.b.d.r.Restarter                      : Stopping application
2020-07-26 10:30:15.187 DEBUG 23080 --- [     Thread-385] onfigReactiveWebServerApplicationContext : Closing org.springframework.boot.web.reactive.context.AnnotationconfigReactiveWebServerApplicationContext@6de721d1,started on Sun Jul 26 10:17:55 SAST 2020
2020-07-26 10:30:15.195 DEBUG 23080 --- [     Thread-385] o.s.c.s.DefaultLifecycleProcessor        : Stopping beans in phase 2147483647
2020-07-26 10:30:15.201 DEBUG 23080 --- [     Thread-385] o.s.c.s.DefaultLifecycleProcessor        : Bean 'webServerGracefulShutdown' completed its stop procedure
2020-07-26 10:30:15.201 DEBUG 23080 --- [     Thread-385] o.s.c.s.DefaultLifecycleProcessor        : Stopping beans in phase 2147483646
2020-07-26 10:30:15.217 DEBUG 23080 --- [     Thread-385] o.s.c.s.DefaultLifecycleProcessor        : Bean 'webServerStartStop' completed its stop procedure
2020-07-26 10:30:15.217 DEBUG 23080 --- [     Thread-385] o.s.c.s.DefaultLifecycleProcessor        : Stopping beans in phase 0
2020-07-26 10:30:19.433 DEBUG 23080 --- [     Thread-385] o.s.b.d.r.Restarter                      : Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@45d8b2bd
2020-07-26 10:30:19.433 DEBUG 23080 --- [     Thread-385] o.s.b.d.r.Restarter                      : Starting application ubuntu.software.web.NcitoAfricaApplication with URLs [file:/C:/Users/alungu5/IdeaProjects/Tubombeko/]
2020-07-26 10:30:19.571 DEBUG 23080 --- [  restartedMain] .c.l.ClasspathLoggingApplicationListener : Application started with classpath: [file:/C:/Users/alungu5/IdeaProjects/Tubombeko/]

。 。 。

    springframework.beans.factory.BeanCreationException: Error creating bean with name 'countryServiceImpl' defined in file [C:\Users\alungu5\IdeaProjects\Tubombeko\service\target\classes\ubuntu\software\service\country\CountryServiceImpl.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class ubuntu.software.service.country.CountryServiceImpl: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.LinkageError-->loader 'app' attempted duplicate class definition for ubuntu.software.service.country.CountryServiceImpl$$EnhancerBySpringCGLIB$$906ca3da. (ubuntu.software.service.country.CountryServiceImpl$$EnhancerBySpringCGLIB$$906ca3da is in module ubuntu.software.service of loader 'app')
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:603) ~[spring-beans-5.2.7.RELEASE.jar:?]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.7.RELEASE.jar:?]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.7.RELEASE.jar:?]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.7.RELEASE.jar:?]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.7.RELEASE.jar:?]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.7.RELEASE.jar:?]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:893) ~[spring-beans-5.2.7.RELEASE.jar:?]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.7.RELEASE.jar:?]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.7.RELEASE.jar:?]
        at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:62) ~[spring-boot-2.3.1.RELEASE.jar:?]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.3.1.RELEASE.jar:?]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.1.RELEASE.jar:?]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.1.RELEASE.jar:?]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.1.RELEASE.jar:?]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.1.RELEASE.jar:?]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.1.RELEASE.jar:?]
        at ubuntu.software.web.NcitoAfricaApplication.main(NcitoAfricaApplication.java:21) [classes/:?]
        at jdk.internal.reflect.NativeMethodaccessorImpl.invoke0(Native Method) ~[?:?]
        at jdk.internal.reflect.NativeMethodaccessorImpl.invoke(NativeMethodaccessorImpl.java:62) ~[?:?]
        at jdk.internal.reflect.DelegatingMethodaccessorImpl.invoke(DelegatingMethodaccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:564) ~[?:?]
        at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.3.1.RELEASE.jar:?]
    Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class ubuntu.software.service.country.CountryServiceImpl: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.LinkageError-->loader 'app' attempted duplicate class definition for ubuntu.software.service.country.CountryServiceImpl$$EnhancerBySpringCGLIB$$906ca3da. (ubuntu.software.service.country.CountryServiceImpl$$EnhancerBySpringCGLIB$$906ca3da is in module ubuntu.software.service of loader 'app')
        at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:208) ~[spring-aop-5.2.7.RELEASE.jar:?]
        at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110) ~[spring-aop-5.2.7.RELEASE.jar:?]
        at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:471) ~[spring-aop-5.2.7.RELEASE.jar:?]
        at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:350) ~[spring-aop-5.2.7.RELEASE.jar:?]
        at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:299) ~[spring-aop-5.2.7.RELEASE.jar:?]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431) ~[spring-beans-5.2.7.RELEASE.jar:?]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.2.7.RELEASE.jar:?]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.7.RELEASE.jar:?]
        ... 21 more
    Caused by: org.springframework.cglib.core.CodeGenerationException: java.lang.LinkageError-->loader 'app' attempted duplicate class definition for ubuntu.software.service.country.CountryServiceImpl$$EnhancerBySpringCGLIB$$906ca3da. (ubuntu.software.service.country.CountryServiceImpl$$EnhancerBySpringCGLIB$$906ca3da is in module ubuntu.software.service of loader 'app')
        at org.springframework.cglib.core.ReflectUtils.defineclass(ReflectUtils.java:558) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:585) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) ~[spring-core-5.2.7.RELEASE.jar:?]
        at java.util.concurrent.Futuretask.run(Futuretask.java:264) ~[?:?]
        at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:134) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:319) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:572) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.cglib.proxy.Enhancer.createclass(Enhancer.java:419) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:57) ~[spring-aop-5.2.7.RELEASE.jar:?]
        at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:205) ~[spring-aop-5.2.7.RELEASE.jar:?]
        at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110) ~[spring-aop-5.2.7.RELEASE.jar:?]
        at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:471) ~[spring-aop-5.2.7.RELEASE.jar:?]
        at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:350) ~[spring-aop-5.2.7.RELEASE.jar:?]
        at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:299) ~[spring-aop-5.2.7.RELEASE.jar:?]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431) ~[spring-beans-5.2.7.RELEASE.jar:?]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.2.7.RELEASE.jar:?]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.7.RELEASE.jar:?]
        ... 21 more
    Caused by: java.lang.LinkageError: loader 'app' attempted duplicate class definition for ubuntu.software.service.country.CountryServiceImpl$$EnhancerBySpringCGLIB$$906ca3da. (ubuntu.software.service.country.CountryServiceImpl$$EnhancerBySpringCGLIB$$906ca3da is in module ubuntu.software.service of loader 'app')
        at java.lang.ClassLoader.defineclass1(Native Method) ~[?:?]
        at java.lang.System$2.defineclass(System.java:2196) ~[?:?]
        at java.lang.invoke.MethodHandles$Lookup.defineclass(MethodHandles.java:1648) ~[?:?]
        at jdk.internal.reflect.GeneratedMethodaccessor43.invoke(Unknown Source) ~[?:?]
        at jdk.internal.reflect.DelegatingMethodaccessorImpl.invoke(DelegatingMethodaccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:564) ~[?:?]
        at org.springframework.cglib.core.ReflectUtils.defineclass(ReflectUtils.java:555) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:585) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) ~[spring-core-5.2.7.RELEASE.jar:?]
        at java.util.concurrent.Futuretask.run(Futuretask.java:264) ~[?:?]
        at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:134) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:319) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:572) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.cglib.proxy.Enhancer.createclass(Enhancer.java:419) ~[spring-core-5.2.7.RELEASE.jar:?]
        at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:57) ~[spring-aop-5.2.7.RELEASE.jar:?]
        at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:205) ~[spring-aop-5.2.7.RELEASE.jar:?]
        at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110) ~[spring-aop-5.2.7.RELEASE.jar:?]
        at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:471) ~[spring-aop-5.2.7.RELEASE.jar:?]
        at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:350) ~[spring-aop-5.2.7.RELEASE.jar:?]
        at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:299) ~[spring-aop-5.2.7.RELEASE.jar:?]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431) ~[spring-beans-5.2.7.RELEASE.jar:?]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.2.7.RELEASE.jar:?]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.7.RELEASE.jar:?]
        ... 21 more

这就是我的CountryServiceImpl的样子

@Service
@Qualifier("CountryServiceImpl")
public class CountryServiceImpl extends BaseService<Country,CountryDto,CountryRepository> implements ICountryService {


    @Lazy
    @Autowired
    private CountryRepository countryRepository;

    @Lazy
    @Autowired
    private IJWTUtil jwtUtil;

    @Override
    public CountryRepository getRepository() {
        return countryRepository;
    }


    @Override
    public Mono<Country> createModel(CountryDto countryDto,Map<String,Claim> claims) {
        Country country = getModelMapper().map(countryDto,Country.class);
        country.setStatus(BaseModel.Status.ENABLED);
        return Mono.just(country);
    }

    @Override
    public Mono<Country> createUpdateModel(CountryDto countryDto,Claim> claims) {
        return getRepository().findById(countryDto.getId())
                .flatMap(country -> Mono.just(country.toBuilder()
                        .name(countryDto.getName())
                        .build()));
    }

    @Override
    public IJWTUtil getJwtUtil() {
        return jwtUtil;
    }
}

我的ICountryService界面

public interface ICountryService extends IBaseService<Country,CountryDto> {
}

我的BaseService Impl

@Transactional
public abstract class BaseService<T extends BaseModel,V extends BaseDto,E extends BaseRepository<T>> implements IBaseService<T,V> {

    @Getter
    private final ModelMapper modelMapper;

    abstract public E getRepository();

    public abstract Mono<T> createModel(V v,Claim> claims);

    public abstract Mono<T> createUpdateModel(V v,Claim> claims);

    public abstract IJWTUtil getJwtUtil();

    public Mono<T> validate(Mono<T> t) {
        return t;
    }

    public Flux<T> validate(Flux<T> t) {
        return t;
    }



    public BaseService() {
        modelMapper = new ModelMapper();
    }

    @Override
    public Mono<ResponseEntity<?>> create(V v,Optional<String> authorizationHeader) {
        Map<String,Claim> claims = authorizationHeader.map(mAuthorizationHeader -> getJwtUtil().getallClaims(mAuthorizationHeader)).orElse(new HashMap<>());
        Mono<T> model = this.createModel(v,claims);
        return create(model,claims)
                .flatMap(__ -> Mono.<ResponseEntity<?>>just(ResponseEntity
                        .status(HttpStatus.CREATED)
                        .body(Response.builder()
                                .payLoad(HttpStatus.CREATED)
                                .build())))
                .switchIfEmpty(Mono.defer(() ->
                        Mono.just(ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
                                .body(Response.builder()
                                        .status(HttpStatus.INTERNAL_SERVER_ERROR)
                                        .message("Unknown error occurred,try again")
                                        .build()))));
    }

    @Override
    public Mono<T> create(Mono<T> t,Claim> claims) {
        return validate(t)
                .flatMap(k -> getRepository().save(k));
    }


    @Override
    public Flux<T> createAll(List<T> t,Claim> claims) {
        return validate(Flux.fromIterable(t))
                .thenmany(getRepository().saveAll(t));
    }
}

最后是我的IBaseService界面

public interface IBaseService<T extends BaseModel,V extends BaseDto> {

    Mono<ResponseEntity<?>> create(V v,Optional<String> authorizationHeader);

    Mono<T> create(Mono<T> t,Claim> claims);

    Flux<T> createAll(List<T> t,Claim> claims);
}

经过阅读后,我发现CGLIB问题通常是由@Transactional注释生成的代理引起的,一种解决方法是将@Transactional放在其父对象上我有,但是在应用程序重启后错误仍然弹出。

iCMS 回答:Spring Boot Webflux应用程序重新启动并导致重复的EnhancerBySpringCGLIB

好吧,所以我找到了罪魁祸首,原来是Java 9 module-info.java,我遇到了使RabbitMq正常工作的问题,所有文件均已正确导入,但它的意思是说错误是由我的module-info.java引起的,因此我将其删除,将其删除后,我还没有遇到这个问题(RabbitMq也起作用),据我所知,它们是未放入需要的允许列表的内部类可以访问我的课程,并且由于该应用程序始终无法运行,因此该应用程序自那时以来一直在运行,没有任何问题。

本文链接:https://www.f2er.com/1863073.html

大家都在问