Skip to content

Commit

Permalink
Merge pull request #317 from devgateway/#315-dgtkit-3.x-devtools
Browse files Browse the repository at this point in the history
Enable spring boot devtools - dgtkit 3.x
  • Loading branch information
developster authored Oct 12, 2020
2 parents ffa1f06 + e2f3037 commit ee94666
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 0 deletions.
15 changes: 15 additions & 0 deletions forms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,18 @@ This module is packaged as a fat jar. For testing purposes, the default configur
`java -Dspring.profiles.active=dev -jar target/forms-0.0.1-SNAPSHOT.jar`

This will start everything, including an embedded Tomcat Web server and all the services attached it.

# Using Spring Boot Developer Tools

This spring add-on allows automatic context reload of beans when resource changes detected
(classes recompiled, other files in classpath changed). This means you do not have to restart your
application when you recompile classes, nor you need paid tools like jrebel for it.

Read more about it [here](https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/using-boot-devtools.html)
A good howto can be found [here](https://www.baeldung.com/spring-boot-devtools)

To enable devtools you need to start the application using java startup property
`spring.devtools.restart.enabled=true`

Wicket integration is done according to section [20.2.6](https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/using-boot-devtools.html#using-boot-devtools-customizing-classload)
of the documentation.
6 changes: 6 additions & 0 deletions forms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
<version>0.0.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.devgateway.toolkit</groupId>
<artifactId>persistence-mongodb</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.devgateway.toolkit.forms.serializer;

import org.apache.wicket.serialize.ISerializer;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.serializer.DefaultDeserializer;
import org.springframework.core.serializer.support.DeserializingConverter;
import org.springframework.core.serializer.support.SerializingConverter;

/**
* A custom serializer is needed to support Spring Boot Devtools. Spring Boot Devtools
* has some limitation with support of serialisation/deserialization support. So we have to
* provide a custom Wicket {@link ISerializer}.
*
* <p>
* <b>20.2.6 Known limitations</b> <br>
* Restart functionality does not work well with objects that are deserialized using a
* standard ObjectInputStream. If you need to deserialize data, you may need to use Spring’s
* ConfigurableObjectInputStream in combination with Thread.currentThread().getContextClassLoader().
* Unfortunately, several third-party libraries deserialize without considering the context classloader.
* If you find such a problem, you will need to request a fix with the original authors.
* </p>
*
* @author Marc Giffing
* @see <a href="https://github.com/spring-projects/spring-boot/issues/3805">Spring Boot Devtools Serializer Issue</a>
*/
public class SpringDevToolsSerializer implements ISerializer {

private Converter<Object, byte[]> serializer = new SerializingConverter();
private Converter<byte[], Object> deserializer;

public SpringDevToolsSerializer() {
this.deserializer = new DeserializingConverter(new DefaultDeserializer(Thread.currentThread()
.getContextClassLoader()));
}

@Override
public byte[] serialize(final Object object) {
return serializer.convert(object);
}

@Override
public Object deserialize(final byte[] data) {
return deserializer.convert(data);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.apache.wicket.settings.RequestCycleSettings.RenderStrategy;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import org.apache.wicket.util.file.Folder;
import org.devgateway.toolkit.forms.serializer.SpringDevToolsSerializer;
import org.devgateway.toolkit.forms.service.SessionFinderService;
import org.devgateway.toolkit.forms.wicket.components.form.SummernoteJpaStorageService;
import org.devgateway.toolkit.forms.wicket.converters.NonNumericFilteredBigDecimalConverter;
Expand Down Expand Up @@ -209,6 +210,8 @@ protected void init() {
guard.addPattern("+*.woff2");
}

getFrameworkSettings().setSerializer(new SpringDevToolsSerializer());

// this ensures that spring DI works for wicket components and pages
// see @SpringBean annotation
getComponentInstantiationListeners().add(new SpringComponentInjector(this, applicationContext));
Expand Down
2 changes: 2 additions & 0 deletions forms/src/main/resources/META-INF/spring-devtools.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
restart.include.wicket-annotation=/wicketstuff-annotation-[\\w-\.]+\.jar
restart.include.wicket-spring=/wicket-spring-[\\w-\.]+\.jar
13 changes: 13 additions & 0 deletions web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,16 @@ Because it gets packaged as a fat jar, starting it is piece of cake:
`java -jar target/web-0.0.1-SNAPSHOT.jar`

This will start everything, including an embedded Tomcat Web server and all the services attached it.

# Using Spring Boot Developer Tools

This spring add-on allows automatic context reload of beans when resource changes detected
(classes recompiled, other files in classpath changed). This means you do not have to restart your
application when you recompile classes, nor you need paid tools like jrebel for it.

Read more about it [here](https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/using-boot-devtools.html)
A good howto can be found [here](https://www.baeldung.com/spring-boot-devtools)

To enable devtools you need to start the application using java startup property
`spring.devtools.restart.enabled=true`

6 changes: 6 additions & 0 deletions web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down

0 comments on commit ee94666

Please sign in to comment.