Skip to content

Commit 9cc9c8c

Browse files
committed
WIP with example
1 parent 4302617 commit 9cc9c8c

27 files changed

+1518
-2
lines changed

.cursor/rules/301-frameworks-spring-boot-core.mdc

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ These guidelines are built upon the following core principles:
1818

1919
## Table of contents
2020

21+
- Rule 0: Spring Boot Main Application Class
2122
- Rule 1: Main Spring Boot Annotations Usage
2223
- Rule 2: Bean Definition and Management
2324
- Rule 3: Configuration Classes and Properties
@@ -27,6 +28,75 @@ These guidelines are built upon the following core principles:
2728
- Rule 7: Bean Minimization and Composition
2829
- Rule 8: Scheduled Tasks and Background Processing
2930

31+
## Rule 0: Spring Boot Main Application Class
32+
33+
Title: Create a Proper Spring Boot Main Application Class
34+
Description: Every Spring Boot application should have a main application class annotated with @SpringBootApplication. This class serves as the entry point and configuration root, combining @Configuration, @EnableAutoConfiguration, and @ComponentScan annotations.
35+
36+
**Good example:**
37+
38+
```java
39+
@SpringBootApplication
40+
public class MainApplication {
41+
42+
public static void main(String[] args) {
43+
SpringApplication.run(MainApplication.class, args);
44+
}
45+
}
46+
47+
// For more complex scenarios with custom configuration
48+
@SpringBootApplication(
49+
scanBasePackages = {
50+
"com.company.app.controller",
51+
"com.company.app.service",
52+
"com.company.app.repository",
53+
"com.company.app.config"
54+
},
55+
exclude = {
56+
DataSourceAutoConfiguration.class,
57+
SecurityAutoConfiguration.class
58+
}
59+
)
60+
```
61+
62+
**Bad Example:**
63+
64+
```java
65+
// Missing @SpringBootApplication annotation
66+
public class MainApplication {
67+
public static void main(String[] args) {
68+
// Manual Spring context setup instead of SpringApplication.run()
69+
ApplicationContext context = new AnnotationConfigApplicationContext();
70+
// Manual configuration - loses Spring Boot benefits
71+
}
72+
}
73+
74+
// Using individual annotations instead of @SpringBootApplication
75+
@Configuration
76+
@EnableAutoConfiguration
77+
@ComponentScan
78+
public class MainApplication { // Verbose and error-prone
79+
public static void main(String[] args) {
80+
SpringApplication.run(MainApplication.class, args);
81+
}
82+
}
83+
84+
// Poor naming and structure
85+
@SpringBootApplication
86+
public class App { // Non-descriptive name
87+
88+
@Autowired
89+
private UserService userService; // Business logic in main class
90+
91+
public static void main(String[] args) {
92+
SpringApplication.run(App.class, args);
93+
94+
// Business logic in main method - should be in separate components
95+
System.out.println("Processing users...");
96+
}
97+
}
98+
```
99+
30100
## Rule 1: Main Spring Boot Annotations Usage
31101

32102
Title: Use Appropriate Spring Boot Annotations for Component Definition

.github/workflows/maven.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ jobs:
1515
distribution: 'graalvm' # See 'Supported distributions' for available options
1616
java-version: '24'
1717
- name: Maven build
18-
run: cd examples/maven-demo && ./mvnw --batch-mode --no-transfer-progress verify --file pom.xml
18+
run: cd examples/maven-demo && ./mvnw --batch-mode --no-transfer-progress verify --file pom.xml
19+
- name: Spring Boot build
20+
run: cd examples/spring-boot-demo/implementation && ./mvnw --batch-mode --no-transfer-progress verify --file pom.xml

examples/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@
22

33
| Example | Notes |
44
|----------|-------|
5-
| 1. Maven demo | Simple Maven demo generated with `jbang setup@jabrena init --maven`. Used to test the behaviour of Cursor rules for Java. |
5+
| Maven demo | Simple Maven demo generated with `jbang setup@jabrena init --maven`. Used to test the behaviour of Cursor rules for Java. |
6+
| Spring Boot demo | Simple Maven demo generated with `jbang setup@jabrena init --spring-boot`. Used to test the behaviour of Cursor rules for Java & Spring Boot. |
7+
8+
9+
## References
10+
11+
- https://github.com/jabrena/spring-boot-relational-database-poc/
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/mvnw text eol=lf
2+
*.cmd text eol=crlf
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
HELP.md
2+
target/
3+
.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**/target/
5+
!**/src/test/**/target/
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
!**/src/main/**/build/
30+
!**/src/test/**/build/
31+
32+
### VS Code ###
33+
.vscode/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
wrapperVersion=3.3.2
18+
distributionType=only-script
19+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.10/apache-maven-3.9.10-bin.zip

0 commit comments

Comments
 (0)