JiroPay
JiroPay

Reputation: 1

SymetricWebServer doesnt create SYM* tables in embedded mode (Spring Boot)

I have a master server node (called root) deployed with standalone install archive and launched with "sym" command line on my machine and on a MySQL DB. => OK.

For my client server nodes, I try to use embedded SymmetricDS in Spring Boot within H2 file DB. (for a desktop application) (I'm using SymmetricDS 3.12.5)

Here is my Spring boot code :

@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();
        File propFile = null;
        try {
            propFile = new ClassPathResource(
                    "symmetric-client.properties").getFile();
            Properties propertiesFile = new Properties();
            propertiesFile.load(new FileReader(propFile));

            ServerSymmetricEngine serverEngine = new ServerSymmetricEngine(dataSource, applicationContext, propertiesFile, false, holder);
            serverEngine.setDeploymentType("server");
            System.out.println(serverEngine.getDeploymentType());
            holder.getEngines().put(propertiesFile.getProperty(ParameterConstants.EXTERNAL_ID), serverEngine);
            //holder.setAutoStart(false);
            servletContext.setAttribute(WebConstants.ATTR_ENGINE_HOLDER, holder);

            serverEngine.setup();
            serverEngine.openRegistration("store", "002");
            serverEngine.start();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Bean
    public ServletRegistrationBean<SymmetricServlet> symServlet() {
        ServletRegistrationBean<SymmetricServlet> bean = new ServletRegistrationBean<>(new SymmetricServlet(), "/sync");
        bean.setLoadOnStartup(1);
        return bean;
    }
}

symmetric-client.properties:

engine.name=store-002
db.driver=org.h2.Driver
db.url=jdbc:h2:tcp://localhost:9090/~/mydb;AUTO_SERVER=TRUE;LOCK_TIMEOUT=60000
db.user=****
db.password=****
registration.url=http://localhost:31415/sync/root-000
group.id=store
external.id=002
job.routing.period.time.ms=5000
job.push.period.time.ms=10000
job.pull.period.time.ms=10000
auto.registration=true
initial.load.create.first=true
auto.config.database=true
start.refresh.cache.job=true
auto.sync.triggers=true
auto.reload = true;
https.verified.server.names=all

application.yml file :

spring:
  application:
    name: myapp
  jpa:
    hibernate:
      ddl-auto: update
      properties:
        dialect: org.hibernate.dialect.H2Dialect
    show-sql: true
    properties:
      hibernate:
        search:
          default:
            directory_provider: filesystem
            indexBase: data/indexes/local/main
  datasource:
    driver-class-name: org.h2.Driver
    url: jdbc:h2:/~/mydb;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE
    username: username
    password: password
  h2:
    console:
      enabled: true
server:
  port: 8183

At the first launch of my app, SymetricWebServer does not create the SYM* tables in serverEngine.setup() step, as I expected.

--- [ restartedMain] o.j.symmetric.AbstractSymmetricEngine : Initializing SymmetricDS database

--- [ restartedMain] o.j.symmetric.db.h2.H2SymmetricDialect : Checking if SymmetricDS tables need created or altered

--- [ restartedMain] o.j.s.service.impl.ConfigurationService : Auto-configuring config channel

--- [restartedMain] ERROR org.springframework.boot.SpringApplication - Application run failed org.jumpmind.db.sql.SqlException: Table "SYM_CHANNEL" not found Table "SYM_CHANNEL" not found; SQL statement

I try to create the symmetric tables in client H2 database with standalone symmetric installation command, then restart my Spring boot app. After that, everything is OK for sync with master node in Spring boot application...

Does embedded SymetricWebServer is able to create automaticaly SYM* tables (if they not exist) on my client H2 database at the first Spring boot execution ?

Did I miss something ?

Upvotes: 0

Views: 163

Answers (0)

Related Questions