SymetricWebServer 未以嵌入式模式启动
SymetricWebServer not starting in embedded mode
我有一个 Spring 使用 SymetricDS 的启动 maven 项目。当我以嵌入式模式启动应用程序时,即使我有 Tomcat 和 Spring 启动,它也在寻找 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
这是为什么?为什么不使用对称服务器下载依赖项?
Maven 对 Jetty 的依赖是 "provided" 因为对称服务器可以构建成 war 可以部署到任意数量的 Web 服务器。这是我如何使用 Spring Boot 提供的 Web 容器将 SymmetricDS 嵌入 Spring Boot 的本质。
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;
}
}
我有一个 Spring 使用 SymetricDS 的启动 maven 项目。当我以嵌入式模式启动应用程序时,即使我有 Tomcat 和 Spring 启动,它也在寻找 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
这是为什么?为什么不使用对称服务器下载依赖项?
Maven 对 Jetty 的依赖是 "provided" 因为对称服务器可以构建成 war 可以部署到任意数量的 Web 服务器。这是我如何使用 Spring Boot 提供的 Web 容器将 SymmetricDS 嵌入 Spring Boot 的本质。
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;
}
}