Skip to content

Commit 4226c8f

Browse files
authored
Bug load JPA Repositories and Entitites (#18)
* reproduced the issue #17 * added own @EnableSpringPersistentTasksJpaRepositories annotation * added helper annotations to register entities and jpa repositories * update UI libs * update doc
1 parent 16b3264 commit 4226c8f

13 files changed

+989
-848
lines changed

core/src/main/java/org/sterl/spring/persistent_tasks/EnableSpringPersistentTasks.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,26 @@
77
import java.lang.annotation.Target;
88

99
import org.springframework.context.annotation.Import;
10+
import org.sterl.spring.persistent_tasks.config.SpringPersistentTasksConfig;
1011

12+
/**
13+
* Enables the spring persistent task services.
14+
*
15+
* <pre>
16+
* @SpringBootApplication
17+
* @EnableSpringPersistentTasks
18+
* public class MyApp {
19+
* }
20+
* </pre>
21+
* <p>Include corresponding annotation if you use:</p>
22+
* <ul>
23+
* <li>@EntityScan -> {@link EnableSpringPersistentTasksEntityScan}</li>
24+
* <li>@EnableJpaRepositories -> {@link EnableSpringPersistentTasksJpaRepositories}</li>
25+
* <li>@EnableEnversRepositories -> {@link EnableSpringPersistentTasksJpaRepositories}</li>
26+
* </ul>
27+
*
28+
* They break the spring auto configuration.
29+
*/
1130
@Target(ElementType.TYPE)
1231
@Retention(RetentionPolicy.RUNTIME)
1332
@Documented
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.sterl.spring.persistent_tasks;
2+
3+
import java.lang.annotation.Documented;
4+
import java.lang.annotation.ElementType;
5+
import java.lang.annotation.Retention;
6+
import java.lang.annotation.RetentionPolicy;
7+
import java.lang.annotation.Target;
8+
9+
import org.springframework.context.annotation.Import;
10+
import org.sterl.spring.persistent_tasks.config.EnableSpringPersistentTasksEntityScanConfig;
11+
12+
/**
13+
* Annotation to include spring persistent task entities if <code>@EntityScan</code> annotation is used.
14+
*
15+
* <pre>
16+
* @SpringBootApplication
17+
* @EntityScan
18+
* @EnableSpringPersistentTasksEntityScan
19+
* @EnableSpringPersistentTasks
20+
* public class MyApp {
21+
* }
22+
* </pre>
23+
*/
24+
@Target(ElementType.TYPE)
25+
@Retention(RetentionPolicy.RUNTIME)
26+
@Documented
27+
@Import(EnableSpringPersistentTasksEntityScanConfig.class)
28+
public @interface EnableSpringPersistentTasksEntityScan {
29+
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.sterl.spring.persistent_tasks;
2+
3+
import java.lang.annotation.Documented;
4+
import java.lang.annotation.ElementType;
5+
import java.lang.annotation.Retention;
6+
import java.lang.annotation.RetentionPolicy;
7+
import java.lang.annotation.Target;
8+
9+
import org.springframework.context.annotation.Import;
10+
import org.sterl.spring.persistent_tasks.config.EnableSpringPersistentTasksJpaRepositoriesConfig;
11+
12+
/**
13+
* Annotation to include spring persistent task repositories if <code>@EnableJpaRepositories</code> annotation is used.
14+
*
15+
* <pre>
16+
* @SpringBootApplication
17+
* @EnableJpaRepositories
18+
* @EnableSpringPersistentTasksJpaRepositories
19+
* @EnableSpringPersistentTasks
20+
* public class MyApp {
21+
* }
22+
* </pre>
23+
*/
24+
@Target(ElementType.TYPE)
25+
@Retention(RetentionPolicy.RUNTIME)
26+
@Documented
27+
@Import(EnableSpringPersistentTasksJpaRepositoriesConfig.class)
28+
public @interface EnableSpringPersistentTasksJpaRepositories {
29+
30+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.sterl.spring.persistent_tasks.config;
2+
3+
import org.springframework.beans.factory.config.BeanDefinition;
4+
import org.springframework.boot.autoconfigure.domain.EntityScan;
5+
import org.springframework.context.annotation.Role;
6+
import org.sterl.spring.persistent_tasks.EnableSpringPersistentTasksEntityScan;
7+
8+
@EntityScan(basePackageClasses = EnableSpringPersistentTasksEntityScan.class)
9+
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
10+
public class EnableSpringPersistentTasksEntityScanConfig {
11+
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.sterl.spring.persistent_tasks.config;
2+
3+
import org.springframework.beans.factory.config.BeanDefinition;
4+
import org.springframework.context.annotation.Role;
5+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
6+
import org.sterl.spring.persistent_tasks.EnableSpringPersistentTasksJpaRepositories;
7+
8+
@EnableJpaRepositories(basePackageClasses = EnableSpringPersistentTasksJpaRepositories.class)
9+
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
10+
public class EnableSpringPersistentTasksJpaRepositoriesConfig {
11+
12+
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
package org.sterl.spring.persistent_tasks;
1+
package org.sterl.spring.persistent_tasks.config;
22

3+
import org.springframework.beans.factory.config.BeanDefinition;
34
import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
45
import org.springframework.context.annotation.ComponentScan;
5-
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.context.annotation.Role;
67
import org.springframework.scheduling.annotation.EnableAsync;
78
import org.springframework.scheduling.annotation.EnableScheduling;
9+
import org.sterl.spring.persistent_tasks.EnableSpringPersistentTasks;
810

9-
@Configuration
1011
@EnableScheduling
1112
@EnableAsync
1213
@AutoConfigurationPackage(basePackageClasses = EnableSpringPersistentTasks.class)
1314
@ComponentScan(basePackageClasses = EnableSpringPersistentTasks.class)
15+
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
1416
public class SpringPersistentTasksConfig {
1517

1618
}

doc/docs/maven-setup.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626
public class ExampleApplication {
2727
```
2828

29+
Include corresponding annotation if you use:
30+
31+
- `@EntityScan` ->` @EnableSpringPersistentTasksEntityScan`
32+
- `@EnableJpaRepositories` -> `@EnableSpringPersistentTasksJpaRepositories`
33+
- `@EnableEnversRepositories` ->` @EnableSpringPersistentTasksJpaRepositories`
34+
35+
They break the spring auto configuration.
36+
2937
# DB using liquibase
3038

3139
Dependency needed to setup the DB using liquibase

example/pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.springframework.boot</groupId>
88
<artifactId>spring-boot-starter-parent</artifactId>
9-
<version>3.3.12</version>
9+
<version>3.4.10</version>
1010
<relativePath /> <!-- lookup parent from repository -->
1111
</parent>
1212

@@ -17,7 +17,7 @@
1717
<!--
1818
<spt.version>2.1.2</spt.version>
1919
-->
20-
<spt.version>2.2.1</spt.version>
20+
<spt.version>2.2.3-SNAPSHOT</spt.version>
2121
</properties>
2222

2323
<dependencies>
@@ -48,6 +48,12 @@
4848
<groupId>org.springframework.boot</groupId>
4949
<artifactId>spring-boot-starter-web</artifactId>
5050
</dependency>
51+
52+
<dependency>
53+
<groupId>org.springframework.data</groupId>
54+
<artifactId>spring-data-envers</artifactId>
55+
</dependency>
56+
5157

5258
<dependency>
5359
<groupId>org.springframework.boot</groupId>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
<properties>
3838
<java.version>21</java.version>
39-
<spring-boot.version>3.4.7</spring-boot.version>
39+
<spring-boot.version>3.4.10</spring-boot.version>
4040
<maven.compiler.source>${java.version}</maven.compiler.source>
4141
<maven.compiler.target>${java.version}</maven.compiler.target>
4242
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

0 commit comments

Comments
 (0)