0

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?

Gábor Csikós
  • 2,787
  • 7
  • 31
  • 57

1 Answers1

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

}
chenson42
  • 1,108
  • 6
  • 13
  • Is this 2 separate classes? – Gábor Csikós May 19 '20 at 13:30
  • @GáborCsikós. No. Looks like the code was pasted twice. I fixed the post. – chenson42 May 19 '20 at 19:02
  • It just hangs at ServerSymmetricEngine serverEngine line – Gábor Csikós May 19 '20 at 20:05
  • Can you share the log? – chenson42 May 20 '20 at 12:10
  • ServerSymmetricEngine(dataSource, applicationContext, properties, false, holder) ServerSymmetricEngine does not have such constuctor – Gábor Csikós May 21 '20 at 19:51
  • As for the log: Error creating bean with name 'domainServerExporter' defined in class path resource [symmetric-jmx.xml]: Error setting property values – Gábor Csikós May 26 '20 at 20:45
  • 1
    This example was from the latest version of SymmetricDS. 3.11.x. It is published here: http://maven.jumpmind.com/repo/ – chenson42 May 26 '20 at 22:29
  • Wow, thank you i was using mavencentral, and there the highest version was 3.5.9. Now it works – Gábor Csikós May 28 '20 at 21:32
  • It still starts as a client with this configuration: INFO [main] o.j.s.AbstractSymmetricEngine - SymmetricDS Node STARTED: nodeId=server groupId=server type=client subType=null name=server softwareVersion=3.11.9 databaseName=H2 databaseVersion=1.4 driverName=H2 JDBC Driver driverVersion=1.4.200 (2019-10-14) uptime=0 sec. – Gábor Csikós May 30 '20 at 21:11
  • 1
    I think that is just a side effect of how we created the engine. The default deployment type is client and we didn't explicitly set it when creating the ServerSymmetricEngine. You can set it to server explicitly if you want. Shouldn't make a difference as it is informational. User setDeploymentType() on the engine to override it. – chenson42 Jun 01 '20 at 11:33
  • Thank you! This is what i did and it started as a server after it. – Gábor Csikós Jun 01 '20 at 13:06