SymetricWebServer不在嵌入式模式下启动

SymetricWebServer不在嵌入式模式下启动

本文介绍了SymetricWebServer不在嵌入式模式下启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有SymetricDS的Spring boot maven项目.当我以嵌入式模式启动应用程序时,即使我具有使用Spring Boot的Tomcat,它也会在寻找Jetty.

I have a Spring boot maven project with SymetricDS. When I start the application in embedded mode, even if I have a Tomcat with Spring boot, it is looking for Jetty.

SymmetricWebServer node = new SymmetricWebServer("server.properties");


<dependency>
   <groupId>org.jumpmind.symmetric</groupId>
   <artifactId>symmetric-server</artifactId>
   <version>3.5.19</version>
</dependency>

例外:

Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/jetty/server/bio/SocketConnector

这是为什么?为什么依赖性不通过symetric-server下载?

Why is this? Why are the dependencies not downloaded with symetric-server?

推荐答案

对Jetty的maven依赖是提供的",因为可以将对称服务器构建为可以部署到任意数量的Web服务器的战争.这是我如何使用Spring Boot提供的Web容器将SymmetricDS嵌入Spring Boot中的本质.

The maven dependency on Jetty is "provided" because symmetric-server can be built to be a war that can be deployed to any number of web servers. Here is the essence of how I would embed SymmetricDS in Spring Boot using Spring Boot's provided web container.

import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.web.ServerSymmetricEngine;
import org.jumpmind.symmetric.web.SymmetricEngineHolder;
import org.jumpmind.symmetric.web.SymmetricServlet;
import org.jumpmind.symmetric.web.WebConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.ServletContext;
import javax.sql.DataSource;
import java.util.Properties;

@Configuration
public class SymDSModule implements ApplicationListener<ApplicationReadyEvent> {

    @Autowired
    ServletContext servletContext;

    @Autowired
    DataSource dataSource;

    @Autowired
    ApplicationContext applicationContext;

    @Override
    final public void onApplicationEvent(ApplicationReadyEvent event) {
        SymmetricEngineHolder holder = new SymmetricEngineHolder();
        Properties properties = new Properties();

        properties.put(ParameterConstants.DATA_LOADER_IGNORE_MISSING_TABLES, "true");
        properties.put(ParameterConstants.TRIGGER_CREATE_BEFORE_INITIAL_LOAD, "false");
        properties.put(ParameterConstants.AUTO_RELOAD_ENABLED, "true");
        properties.put(ParameterConstants.AUTO_REGISTER_ENABLED, "true");

        ServerSymmetricEngine serverEngine = new ServerSymmetricEngine(dataSource, applicationContext, properties, false, holder);

        holder.getEngines().put(properties.getProperty(ParameterConstants.EXTERNAL_ID), serverEngine);
        holder.setAutoStart(false);
        servletContext.setAttribute(WebConstants.ATTR_ENGINE_HOLDER, holder);

        serverEngine.setup();
        serverEngine.start();
    }

    @Bean
    public ServletRegistrationBean<SymmetricServlet> symServlet() {
        ServletRegistrationBean<SymmetricServlet> bean = new ServletRegistrationBean<>(new SymmetricServlet(), "/sync");
        bean.setLoadOnStartup(1);
        return bean;
    }

}

这篇关于SymetricWebServer不在嵌入式模式下启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 03:31