问题
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