Skip to content

Commit ef601d8

Browse files
committed
ENH: default using ebean-agent.
1 parent b50981d commit ef601d8

File tree

5 files changed

+99
-8
lines changed

5 files changed

+99
-8
lines changed

pom.xml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>io.github.hexagonframework.boot</groupId>
77
<artifactId>spring-data-ebean-spring-boot</artifactId>
8-
<version>1.0.0.RELEASE</version>
8+
<version>1.1.0.RELEASE</version>
99
<name>Spring data ebean for spring boot</name>
1010
<description>Spring boot support for spring data ebean</description>
1111
<packaging>pom</packaging>
@@ -47,6 +47,7 @@
4747
<properties>
4848
<spring-boot.version>1.5.10.RELEASE</spring-boot.version>
4949
<spring-data-ebean.version>1.2.7.RELEASE</spring-data-ebean.version>
50+
<ebean-agent.version>11.10.1</ebean-agent.version>
5051
</properties>
5152

5253
<profiles>
@@ -125,12 +126,22 @@
125126
<dependency>
126127
<groupId>io.github.hexagonframework.boot</groupId>
127128
<artifactId>spring-boot-autoconfigure-data-ebean</artifactId>
128-
<version>1.0.0.RELEASE</version>
129+
<version>1.1.0.RELEASE</version>
129130
</dependency>
130131
<dependency>
131132
<groupId>io.github.hexagonframework.boot</groupId>
132133
<artifactId>spring-boot-starter-data-ebean</artifactId>
133-
<version>1.0.0.RELEASE</version>
134+
<version>1.1.0.RELEASE</version>
135+
</dependency>
136+
<dependency>
137+
<groupId>io.ebean</groupId>
138+
<artifactId>ebean-agent</artifactId>
139+
<version>${ebean-agent.version}</version>
140+
</dependency>
141+
<dependency>
142+
<groupId>org.avaje</groupId>
143+
<artifactId>avaje-agentloader</artifactId>
144+
<version>2.1.2</version>
134145
</dependency>
135146
</dependencies>
136147
</dependencyManagement>

spring-boot-autoconfigure-data-ebean/pom.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
<parent>
77
<groupId>io.github.hexagonframework.boot</groupId>
88
<artifactId>spring-data-ebean-spring-boot</artifactId>
9-
<version>1.0.0.RELEASE</version>
9+
<version>1.1.0.RELEASE</version>
1010
</parent>
1111
<groupId>io.github.hexagonframework.boot</groupId>
1212
<artifactId>spring-boot-autoconfigure-data-ebean</artifactId>
13-
<version>1.0.0.RELEASE</version>
13+
<version>1.1.0.RELEASE</version>
1414
<name>spring boot autoconfigure for spring data ebean</name>
1515
<description>Autoconfigure for using Spring Data Ebean</description>
1616

@@ -25,6 +25,16 @@
2525
<artifactId>spring-data-ebean</artifactId>
2626
<optional>true</optional>
2727
</dependency>
28+
<dependency>
29+
<groupId>io.ebean</groupId>
30+
<artifactId>ebean-agent</artifactId>
31+
<optional>true</optional>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.avaje</groupId>
35+
<artifactId>avaje-agentloader</artifactId>
36+
<optional>true</optional>
37+
</dependency>
2838
</dependencies>
2939

3040
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.springframework.boot.autoconfigure.data.ebean;
2+
3+
import org.avaje.agentloader.AgentLoader;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
import org.springframework.beans.BeansException;
7+
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
8+
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
9+
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
10+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
11+
import org.springframework.context.annotation.Configuration;
12+
import org.springframework.core.Ordered;
13+
import org.springframework.core.PriorityOrdered;
14+
15+
/**
16+
* @author Xuegui Yuan
17+
*/
18+
@Configuration
19+
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE)
20+
@ConditionalOnClass(AgentLoader.class)
21+
public class EbeanAgentAutoConfiguration implements BeanFactoryPostProcessor, PriorityOrdered {
22+
private static final Logger log = LoggerFactory.getLogger(EbeanAgentAutoConfiguration.class);
23+
24+
public EbeanAgentAutoConfiguration() {
25+
load(); // Spring has already evaluated the @ConditionalOnClass
26+
}
27+
28+
private static void load() {
29+
if (!AgentLoader.loadAgentFromClasspath("ebean-agent", "debug=1")) {
30+
log.debug("ebean-agent not loaded");
31+
}
32+
}
33+
34+
/**
35+
* Loads the Ebean agent if the agent-loader and the agent itself are present
36+
* on the classpath, or does nothing otherwise.
37+
* <p>
38+
* Do not call this method from a static initializer as this can lead to a JVM
39+
* deadlock (the agent attach thread will attempt to acquire the class loader
40+
* lock, which is held during static initialization).
41+
*/
42+
public static void enable() {
43+
try {
44+
load();
45+
} catch (NoClassDefFoundError e) {
46+
/* ignored */
47+
}
48+
}
49+
50+
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
51+
// We're not actually doing anything with the BeanFactory, but implementing
52+
// BeanFactoryPostProcessor ensures we get instantiated early, ideally
53+
// before anybody has a chance to load any entity classes we want to
54+
// enhance.
55+
}
56+
57+
public int getOrder() {
58+
return Ordered.HIGHEST_PRECEDENCE;
59+
}
60+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Auto Configure
22
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
3-
org.springframework.boot.autoconfigure.data.ebean.EbeanRepositoriesAutoConfiguration
3+
org.springframework.boot.autoconfigure.data.ebean.EbeanRepositoriesAutoConfiguration,\
4+
org.springframework.boot.autoconfigure.data.ebean.EbeanAgentAutoConfiguration

spring-boot-starter-data-ebean/pom.xml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
<parent>
77
<groupId>io.github.hexagonframework.boot</groupId>
88
<artifactId>spring-data-ebean-spring-boot</artifactId>
9-
<version>1.0.0.RELEASE</version>
9+
<version>1.1.0.RELEASE</version>
1010
</parent>
1111
<groupId>io.github.hexagonframework.boot</groupId>
1212
<artifactId>spring-boot-starter-data-ebean</artifactId>
13-
<version>1.0.0.RELEASE</version>
13+
<version>1.1.0.RELEASE</version>
1414
<name>spring boot starter for spring data ebean</name>
1515
<description>Starter for using Spring Data Ebean</description>
1616

@@ -19,6 +19,15 @@
1919
<groupId>io.github.hexagonframework.data</groupId>
2020
<artifactId>spring-data-ebean</artifactId>
2121
</dependency>
22+
<dependency>
23+
<groupId>io.ebean</groupId>
24+
<artifactId>ebean-agent</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.avaje</groupId>
28+
<artifactId>avaje-agentloader</artifactId>
29+
<version>2.1.2</version>
30+
</dependency>
2231
<dependency>
2332
<groupId>io.github.hexagonframework.boot</groupId>
2433
<artifactId>spring-boot-autoconfigure-data-ebean</artifactId>

0 commit comments

Comments
 (0)