SymetricWebServer not starting in embedded mode

£可爱£侵袭症+ 提交于 2020-06-09 05:33:10

问题


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:

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

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


回答1:


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;
    }

}


来源:https://stackoverflow.com/questions/61840245/symetricwebserver-not-starting-in-embedded-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!