SymetricWebServer不在嵌入式模式下启动
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SymetricWebServer不在嵌入式模式下启动相关的知识,希望对你有一定的参考价值。
我有一个带有SymetricDS的Spring boot maven项目。当我以嵌入式模式启动应用程序时,即使我具有带有Spring引导程序的Tomcat,它也在寻找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下载?
答案
“提供了对Jetty的maven依赖,因为可以将对称服务器构建为一场可以部署到任意数量的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;
以上是关于SymetricWebServer不在嵌入式模式下启动的主要内容,如果未能解决你的问题,请参考以下文章