Skip to content

Support for Spring Boot DevTools Restart #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# 2.3.0

* Add support for shuting down the storage during application shutdown
* By default only enabled when Spring DevTools are active
* This should fix "StorageExceptionInitialization: Active storage for ... already exists" errors during DevTools restart
* Added [Jakarta Bean Validation Constraints](https://jakarta.ee/learn/docs/jakartaee-tutorial/current/beanvalidation/bean-validation/bean-validation.html#_using_jakarta_bean_validation_constraints) with Hibernate validator for entities.

# 2.2.2
Expand Down
6 changes: 3 additions & 3 deletions docs/antora.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: ROOT
title: Spring-Data-Eclipse-Store
version: master
display_version: '2.2.2'
display_version: '2.3.0'
start_page: index.adoc
nav:
- modules/ROOT/nav.adoc
asciidoc:
attributes:
product-name: 'Spring-Data-Eclipse-Store'
display-version: '2.2.2'
maven-version: '2.2.2'
display-version: '2.3.0'
maven-version: '2.3.0'
page-editable: false
page-out-of-support: false
21 changes: 21 additions & 0 deletions docs/modules/ROOT/pages/configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,24 @@ public class DemoConfiguration extends EclipseStoreClientConfiguration
The method ``createEmbeddedStorageFoundation`` could return a much more complicated ``EmbeddedStorageFoundation`` as described here in the https://docs.eclipsestore.io/manual/storage/configuration/index.html[EclipseStore documentation about configuration and foundations].

This also enables you to use multiple EclipseStore-Storages in one project. See the https://github.com/xdev-software/spring-data-eclipse-store/tree/develop/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/dual/storage[Dual storages demo].

== Properties

In general properties from EclipseStore can be used.
See https://docs.eclipsestore.io/manual/storage/configuration/properties.html[EclipseStore - Properties].

Here the {product-name}-Properties are displayed (all must be prefixed with ``spring-data-eclipse-store``):

[cols="1,1"]
|===
|https://github.com/xdev-software/spring-data-eclipse-store/tree/develop/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/config/EclipseStoreClientConfiguration.java[context-close-shutdown-storage.enabled] [[context-close-shutdown-storage]]
| If enabled, the application listens to the ``ContextClosedEvent`` and shuts the storage down if the restart of the spring-dev-tools is enabled (see xref:known-issues.adoc#spring-dev-tools[Known issues] and https://docs.spring.io/spring-boot/api/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.Restart.html[DevToolProperties])

Default: ``true``

|https://github.com/xdev-software/spring-data-eclipse-store/tree/develop/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/config/EclipseStoreClientConfiguration.java[context-close-shutdown-storage.only-when-dev-tools]
|If this and ``context-close-shutdown-storage.enabled`` are true, the application listens to the ``ContextClosedEvent`` and shuts the storage down **only if** the spring-dev-tools are present in the ClassLoader (see xref:known-issues.adoc#spring-dev-tools[Known issues])

Default: ``true``


21 changes: 6 additions & 15 deletions docs/modules/ROOT/pages/known-issues.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,14 @@ This helps you keep your data up to date regardless of the current version.

We created https://github.com/xdev-software/spring-data-eclipse-store/issues/33[an issue] for that but right now we *do not support XDEVs MicroMigration*.

== Spring Developer Tools
== Spring Developer Tools [[spring-dev-tools]]

Using https://docs.spring.io/spring-boot/reference/using/devtools.html[Spring Developer Tools] (`spring-boot-devtools`) can lead to serious issues in your project.
That is manly due to the https://docs.spring.io/spring-boot/reference/using/devtools.html#using.devtools.livereload[LiveReload feature] and the usage of a "Restart Classloader".
That is manly due to the https://docs.spring.io/spring-boot/reference/using/devtools.html#using.devtools.livereload[LiveReload feature] and the usage of a "Restart ClassLoader".
It derives from the https://docs.eclipsestore.io/manual/misc/integrations/spring-boot.html#_spring_dev_tools[issue with EclipseStore].

This leads to problems within EclipseStore and can cause issues with discovering beans (https://github.com/spring-projects/spring-boot/issues/41011[Example Issue]).
To mitigate this issue, {product-name} listens to the closing of the Spring-Context and shuts down the storage.
This **should** handle most problems with the ClassLoader.
Restarting the storage leads to a reloading of all entities and may take some time, yet circumvents the Restart ClassLoader Issue.

If you must use the Spring Developer Tools, make sure to https://docs.spring.io/spring-boot/reference/using/devtools.html#using.devtools.restart.disable[disable restart].

[source,java,title="Example how to disable restart"]
----
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
System.setProperty("spring.devtools.restart.enabled", "false");
SpringApplication.run(MyApplication.class, args);
}
}
----
The behavior can be configured through xref:configuration.adoc#context-close-shutdown-storage[Properties] and is implemented in the https://github.com/xdev-software/spring-data-eclipse-store/tree/develop/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/config/EclipseStoreClientConfiguration.java[EclipseStoreClientConfiguration.java].
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>software.xdev</groupId>
<artifactId>spring-data-eclipse-store-root</artifactId>
<version>2.2.3-SNAPSHOT</version>
<version>2.3.0-SNAPSHOT</version>
<packaging>pom</packaging>

<organization>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-eclipse-store-benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<parent>
<groupId>software.xdev</groupId>
<artifactId>spring-data-eclipse-store-root</artifactId>
<version>2.2.3-SNAPSHOT</version>
<version>2.3.0-SNAPSHOT</version>
</parent>

<artifactId>spring-data-eclipse-store-benchmark</artifactId>
<version>2.2.3-SNAPSHOT</version>
<version>2.3.0-SNAPSHOT</version>
<packaging>jar</packaging>

<inceptionYear>2023</inceptionYear>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-eclipse-store-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>software.xdev</groupId>
<artifactId>spring-data-eclipse-store-root</artifactId>
<version>2.2.3-SNAPSHOT</version>
<version>2.3.0-SNAPSHOT</version>
</parent>

<artifactId>spring-data-eclipse-store-demo</artifactId>
<version>2.2.3-SNAPSHOT</version>
<version>2.3.0-SNAPSHOT</version>
<packaging>jar</packaging>

<organization>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.nio.file.Path;

import org.eclipse.serializer.reflect.ClassLoaderProvider;
import org.eclipse.store.integrations.spring.boot.types.configuration.EclipseStoreProperties;
import org.eclipse.store.integrations.spring.boot.types.factories.EmbeddedStorageFoundationFactory;
import org.eclipse.store.storage.embedded.types.EmbeddedStorage;
Expand All @@ -28,10 +29,11 @@ public class ComplexConfiguration extends EclipseStoreClientConfiguration
@Autowired
public ComplexConfiguration(
final EclipseStoreProperties defaultEclipseStoreProperties,
final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider
final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider,
final ClassLoaderProvider classLoaderProvider
)
{
super(defaultEclipseStoreProperties, defaultEclipseStoreProvider);
super(defaultEclipseStoreProperties, defaultEclipseStoreProvider, classLoaderProvider);
}

/**
Expand All @@ -45,7 +47,11 @@ public ComplexConfiguration(
@Override
public EmbeddedStorageFoundation<?> createEmbeddedStorageFoundation()
{
return EmbeddedStorage.Foundation(Storage.Configuration(Storage.FileProvider(Path.of(STORAGE_PATH))));
final EmbeddedStorageFoundation<?> storageFoundation =
EmbeddedStorage.Foundation(Storage.Configuration(Storage.FileProvider(Path.of(STORAGE_PATH))));
// This is only needed, if a different ClassLoader is used (e.g. when using spring-dev-tools)
storageFoundation.getConnectionFoundation().setClassLoaderProvider(this.getClassLoaderProvider());
return storageFoundation;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.nio.file.Path;

import org.eclipse.serializer.reflect.ClassLoaderProvider;
import org.eclipse.store.integrations.spring.boot.types.configuration.EclipseStoreProperties;
import org.eclipse.store.integrations.spring.boot.types.factories.EmbeddedStorageFoundationFactory;
import org.eclipse.store.storage.embedded.types.EmbeddedStorage;
Expand All @@ -23,15 +24,15 @@
@EnableEclipseStoreRepositories
public class PersistenceInvoiceConfiguration extends EclipseStoreClientConfiguration
{

public static final String STORAGE_PATH = "storage-invoice";

@Autowired
protected PersistenceInvoiceConfiguration(
final EclipseStoreProperties defaultEclipseStoreProperties,
final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider)
final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider,
final ClassLoaderProvider classLoaderProvider)
{
super(defaultEclipseStoreProperties, defaultEclipseStoreProvider);
super(defaultEclipseStoreProperties, defaultEclipseStoreProvider, classLoaderProvider);
}

/**
Expand All @@ -45,6 +46,10 @@ protected PersistenceInvoiceConfiguration(
@Override
public EmbeddedStorageFoundation<?> createEmbeddedStorageFoundation()
{
return EmbeddedStorage.Foundation(Storage.Configuration(Storage.FileProvider(Path.of(STORAGE_PATH))));
final EmbeddedStorageFoundation<?> storageFoundation =
EmbeddedStorage.Foundation(Storage.Configuration(Storage.FileProvider(Path.of(STORAGE_PATH))));
// This is only needed, if a different ClassLoader is used (e.g. when using spring-dev-tools)
storageFoundation.getConnectionFoundation().setClassLoaderProvider(getClassLoaderProvider());
return storageFoundation;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package software.xdev.spring.data.eclipse.store.demo.dual.storage.person;

import org.eclipse.serializer.reflect.ClassLoaderProvider;
import org.eclipse.store.integrations.spring.boot.types.configuration.ConfigurationPair;
import org.eclipse.store.integrations.spring.boot.types.configuration.EclipseStoreProperties;
import org.eclipse.store.integrations.spring.boot.types.factories.EmbeddedStorageFoundationFactory;
Expand Down Expand Up @@ -31,9 +32,10 @@ public class PersistencePersonConfiguration extends EclipseStoreClientConfigurat
public PersistencePersonConfiguration(
final EclipseStoreProperties defaultEclipseStoreProperties,
final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider,
final EclipseStoreProperties properties)
final EclipseStoreProperties properties,
final ClassLoaderProvider classLoaderProvider)
{
super(defaultEclipseStoreProperties, defaultEclipseStoreProvider);
super(defaultEclipseStoreProperties, defaultEclipseStoreProvider, classLoaderProvider);
this.foundation = defaultEclipseStoreProvider;
this.properties = properties;
}
Expand Down
4 changes: 2 additions & 2 deletions spring-data-eclipse-store-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>software.xdev</groupId>
<artifactId>spring-data-eclipse-store-root</artifactId>
<version>2.2.3-SNAPSHOT</version>
<version>2.3.0-SNAPSHOT</version>
</parent>

<artifactId>spring-data-eclipse-store-jpa</artifactId>
<version>2.2.3-SNAPSHOT</version>
<version>2.3.0-SNAPSHOT</version>
<packaging>jar</packaging>

<inceptionYear>2023</inceptionYear>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.nio.file.Path;

import org.eclipse.serializer.reflect.ClassLoaderProvider;
import org.eclipse.store.integrations.spring.boot.types.configuration.EclipseStoreProperties;
import org.eclipse.store.integrations.spring.boot.types.factories.EmbeddedStorageFoundationFactory;
import org.springframework.beans.factory.DisposableBean;
Expand Down Expand Up @@ -45,9 +46,10 @@ public class TestConfiguration extends EclipseStoreClientConfiguration implement
@Autowired
protected TestConfiguration(
final EclipseStoreProperties defaultEclipseStoreProperties,
final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider)
final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider,
final ClassLoaderProvider classLoaderProvider)
{
super(defaultEclipseStoreProperties, defaultEclipseStoreProvider);
super(defaultEclipseStoreProperties, defaultEclipseStoreProvider, classLoaderProvider);
}

@EventListener
Expand Down
2 changes: 1 addition & 1 deletion spring-data-eclipse-store/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>software.xdev</groupId>
<artifactId>spring-data-eclipse-store</artifactId>
<version>2.2.3-SNAPSHOT</version>
<version>2.3.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>spring-data-eclipse-store</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ private <T> void createRepositoryForType(
storageInstance,
new SupportedChecker.Implementation(),
storageInstance,
this.configuration.getValidator()
this.configuration.getValidator(),
this.configuration.getClassLoaderProvider()
),
domainClass,
new EclipseStoreTransactionManager(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.serializer.persistence.binary.jdk17.java.util.BinaryHandlerImmutableCollectionsSet12;
import org.eclipse.serializer.persistence.types.Storer;
import org.eclipse.serializer.reference.ObjectSwizzling;
import org.eclipse.serializer.reflect.ClassLoaderProvider;
import org.eclipse.store.storage.embedded.types.EmbeddedStorageFoundation;
import org.eclipse.store.storage.embedded.types.EmbeddedStorageManager;
import org.eclipse.store.storage.types.StorageManager;
Expand Down Expand Up @@ -69,6 +70,7 @@ public class EclipseStoreStorage
*/
private final Map<Class<?>, VersionManager<?>> versionManagers = new ConcurrentHashMap<>();
private final EclipseStoreStorageFoundationProvider foundationProvider;
private final ClassLoaderProvider classLoaderProvider;
private EntitySetCollector entitySetCollector;
private PersistableChecker persistenceChecker;
private EmbeddedStorageManager storageManager;
Expand All @@ -81,6 +83,7 @@ public class EclipseStoreStorage
public EclipseStoreStorage(final EclipseStoreClientConfiguration storeConfiguration)
{
this.foundationProvider = storeConfiguration;
this.classLoaderProvider = storeConfiguration.getClassLoaderProvider();
}

private StorageManager getInstanceOfStorageManager()
Expand All @@ -94,6 +97,11 @@ public WorkingCopyRegistry getRegistry()
return this.registry;
}

public ClassLoaderProvider getClassLoaderProvider()
{
return this.classLoaderProvider;
}

private synchronized void ensureEntitiesInRoot()
{
if(this.storageManager == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package software.xdev.spring.data.eclipse.store.repository.config;

import org.eclipse.serializer.reflect.ClassLoaderProvider;
import org.eclipse.store.integrations.spring.boot.types.configuration.EclipseStoreProperties;
import org.eclipse.store.integrations.spring.boot.types.factories.EmbeddedStorageFoundationFactory;
import org.springframework.context.annotation.Configuration;
Expand All @@ -29,8 +30,9 @@ public class DefaultEclipseStoreClientConfiguration extends EclipseStoreClientCo
{
protected DefaultEclipseStoreClientConfiguration(
final EclipseStoreProperties defaultEclipseStoreProperties,
final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider)
final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider,
final ClassLoaderProvider classLoaderProvider)
{
super(defaultEclipseStoreProperties, defaultEclipseStoreProvider);
super(defaultEclipseStoreProperties, defaultEclipseStoreProvider, classLoaderProvider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package software.xdev.spring.data.eclipse.store.repository.config;

import org.eclipse.serializer.reflect.ClassLoaderProvider;
import org.eclipse.store.integrations.spring.boot.types.configuration.EclipseStoreProperties;
import org.eclipse.store.integrations.spring.boot.types.factories.EmbeddedStorageFoundationFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand All @@ -29,8 +30,12 @@ public class DefaultEclipseStoreClientConfigurationFactory
@ConditionalOnMissingBean(EclipseStoreClientConfiguration.class)
public DefaultEclipseStoreClientConfiguration getEclipseStoreClientConfiguration(
final EclipseStoreProperties defaultEclipseStoreProperties,
final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider)
final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider,
final ClassLoaderProvider classLoaderProvider)
{
return new DefaultEclipseStoreClientConfiguration(defaultEclipseStoreProperties, defaultEclipseStoreProvider);
return new DefaultEclipseStoreClientConfiguration(
defaultEclipseStoreProperties,
defaultEclipseStoreProvider,
classLoaderProvider);
}
}
Loading