Ошибка создания бина с именем primeLocateCometDService при весенней загрузке 1.5.19 с CometD 3.0.9 и tomcat 8.5.37 - PullRequest
0 голосов
/ 11 июня 2019

Я просто обновляю проект tomcat до проекта весенней загрузки с CometD.Вот два класса сервисов с именами: PrimeLocateCometDService & AbstractRealtimeCometDPublishService

При запуске проекта произошла ошибка.

public AbstractRealtimeCometDPublishService(BayeuxServer bayeuxServer, String sessionName) {
        this.bayeuxServer = bayeuxServer;
        this.localSession = bayeuxServer.newLocalSession(sessionName);
        this.localSession.handshake();
    }

Рукопожатие выдаст исключение nullpointerexception.

package com.citi.pf.realtime;

import javax.servlet.ServletContext;
import javax.servlet.ServletRegistration;

import org.cometd.annotation.AnnotationCometDServlet;
import org.cometd.bayeux.server.BayeuxServer;
import org.cometd.server.BayeuxServerImpl;
import org.cometd.server.transport.JSONPTransport;
import org.cometd.server.transport.JSONTransport;
import org.cometd.websocket.server.WebSocketTransport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.autoconfigure.security.FallbackWebSecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration;
import org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.ImportResource;

import com.citi.pf.portal.lib.util.ENVUtils;

@SpringBootApplication
@ImportResource({
                 //webapp
                 "classpath:META-INF/realtime/pf-realtime-webapp-context.xml",
                 "classpath:WEB-INF/realtime/comet-config.xml",
                 "classpath:WEB-INF/realtime/webmvc-config.xml",
                 "classpath:pfGFIConfigSrvc.xml",
                 //core
                 "classpath:META-INF/realtime/pf-realtime-core-context.xml",
                 //security
                 "classpath:META-INF/realtime/pf-realtime-security-context.xml",
                //prime-locate
                 "classpath:META-INF/realtime/prime-locate-integration-context.xml",
                 "classpath:META-INF/realtime/prime-locate-jndi-context.xml",
                 //prime-locate-cometd
                 "classpath:META-INF/realtime/prime-locate-cometd-integration-context.xml",
                 "classpath:META-INF/realtime/prime-locate-cometd-jndi-context.xml",
                 //prime-notification
                 "classpath:META-INF/realtime/prime-notification-cometd-integration-context.xml",
                 "classpath:META-INF/realtime/prime-notification-cometd-jndi-context.xml",
                 //prime-query
                 "classpath:META-INF/realtime/prime-query-integration-context.xml",
                 "classpath:META-INF/realtime/prime-query-jndi-context.xml",
                 //prime-wire
                 "classpath:META-INF/realtime/prime-wire-integration-context.xml",
                 "classpath:META-INF/realtime/prime-wire-jndi-context.xml"
                 })
@ServletComponentScan
@ComponentScan
@EnableAutoConfiguration(exclude= { 
        DataSourceAutoConfiguration.class,
        JmsAutoConfiguration.class, 
        MongoAutoConfiguration.class, 
        MongoDataAutoConfiguration.class, 
        MultipartAutoConfiguration.class, 
        SecurityAutoConfiguration.class, 
        SecurityAutoConfiguration.class, 
        FallbackWebSecurityAutoConfiguration.class,
        OAuth2AutoConfiguration.class})
public class PFRealtimeServicesApplication extends SpringBootServletInitializer implements ServletContextInitializer{

private static final Logger logger = LoggerFactory.getLogger(PFRealtimeServicesApplication.class);

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(PFRealtimeServicesApplication.class);
}

public static void main(String[] args) {
    ENVUtils.registerEnvName("env"); 
    ENVUtils.registerRunningSystem("REALTIME");
    logger.info("Enter Realtime services application.");
    SpringApplication.run(PFRealtimeServicesApplication.class,args);
}

@Override
public void onStartup(ServletContext servletContext) {
    ServletRegistration.Dynamic cometdServlet = servletContext.addServlet("cometd", AnnotationCometDServlet.class);
    cometdServlet.addMapping("/cometd/*");
    cometdServlet.setAsyncSupported(true);
    cometdServlet.setLoadOnStartup(1);
    //cometdServlet.setInitParameter("PrimeLocateCometDService", PrimeLocateCometDService.class.getName());
    //cometdServlet.setInitParameter("PrimeNotificationCometDService", PrimeNotificationCometDService.class.getName());
}

@Bean
protected ServletContextInitializer servletInitializer() {
    return servletContext -> servletContext.setAttribute(BayeuxServer.ATTRIBUTE, bayeuxServer(servletContext));
}

@Bean
@DependsOn("servletInitializer")
protected BayeuxServer bayeuxServer(ServletContext servletContext) {
    BayeuxServerImpl bean = new BayeuxServerImpl();
    bean.setTransports(new WebSocketTransport(bean), new JSONTransport(bean), new JSONPTransport(bean));
    servletContext.setAttribute(BayeuxServer.ATTRIBUTE, bean);
    bean.setOption(ServletContext.class.getName(), servletContext);
    bean.setOption("ws.cometdURLMapping", "/cometd/*");
    return bean;
}
}

Надеюсь, что компонент PrimeLocateCometDService может быть успешно создан.

1 Ответ

0 голосов
/ 12 июня 2019

Мой проект использует Spring Boot 1.5.19 с CometD 3.0.9 и Tomcat 8.5.37.(1) @ImportResource импортирует все xml-файлы в Application.java (2) Удалить (в xml-файле)

                <bean id="websocketTransport" class="org.cometd.websocket.server.WebSocketTransport">
                    <constructor-arg ref="bayeux" />
                </bean>

(3) Приложение расширяет SpringBootServletInitializer и реализует ServletContextInitializer

       @Override
    public void onStartup(ServletContext servletContext) {
        ServletRegistration.Dynamic cometdServlet = servletContext.addServlet("cometd", 
                AnnotationCometDServlet.class);
        cometdServlet.addMapping("/cometd/*");
        cometdServlet.setAsyncSupported(true);
        cometdServlet.setLoadOnStartup(1);
    }

(4) pom.xml Удалить:

                        <dependency>
                <groupId>org.cometd.java</groupId>
                <artifactId>cometd-java-websocket-javax-server</artifactId>
                <version>3.0.9</version>
            </dependency>

Добавить:

                       <dependency>
                <groupId>org.cometd.java</groupId>
                <artifactId>cometd-java-websocket-javax-server</artifactId>
                <version>3.0.9</version>
            </dependency>

Я думаю, все это повлияет на CometD с помощью Spring Boot.Надеюсь, это кому-нибудь поможет.

...