Coder Social home page Coder Social logo

使用@ServerEndpoint修饰但不用@Component时,其它Bean注入该Bean时会报 bean could not be found 异常 about netty-websocket-spring-boot-starter HOT 2 OPEN

niezhiliang avatar niezhiliang commented on June 12, 2024
使用@ServerEndpoint修饰但不用@Component时,其它Bean注入该Bean时会报 bean could not be found 异常

from netty-websocket-spring-boot-starter.

Comments (2)

niezhiliang avatar niezhiliang commented on June 12, 2024

我尝试的改了一下这个问题,ServerEndpointExporter 再实现一个后置处理器接口 BeanDefinitionRegistryPostProcessor,registerEndpoints中的scanPackage方法放到postProcessBeanFactory方法中执行,让扫描提前执行,就不会再报异常
`public class ServerEndpointExporter extends ApplicationObjectSupport implements SmartInitializingSingleton, BeanFactoryAware, ResourceLoaderAware,BeanDefinitionRegistryPostProcessor {

@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {

}

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
    ApplicationContext context = getApplicationContext();
    scanPackage(context);
}

protected void registerEndpoints() {
    ApplicationContext context = getApplicationContext();
    // scanPackage(context);

    String[] endpointBeanNames = context.getBeanNamesForAnnotation(ServerEndpoint.class);
    Set<Class<?>> endpointClasses = new LinkedHashSet<>();
    for (String beanName : endpointBeanNames) {
        endpointClasses.add(context.getType(beanName));
    }

    for (Class<?> endpointClass : endpointClasses) {
        if (ClassUtils.isCglibProxyClass(endpointClass)) {
            registerEndpoint(endpointClass.getSuperclass());
        } else {
            registerEndpoint(endpointClass);
        }
    }

    init();
}

}`

from netty-websocket-spring-boot-starter.

liliexuan avatar liliexuan commented on June 12, 2024

我怎么感觉你的用法跟我的相反了,不是应该是MyWebSocket注入其他bean吗

from netty-websocket-spring-boot-starter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.