https://github.com/maearon/spring-boilerplate
Social App Angular 19 with Ngrx AngularHttpClient + Spring Boot ActiveStorage app provide two annotation │ └── HasOneAttached.java │ └── HasManyAttached.java to attach file single or multiple file to any model entity
https://github.com/maearon/spring-boilerplate
java jwt lombok postgresql spring spring-boot spring-boot-3 spring-data-jpa spring-security spring-validation
Last synced: about 2 months ago
JSON representation
Social App Angular 19 with Ngrx AngularHttpClient + Spring Boot ActiveStorage app provide two annotation │ └── HasOneAttached.java │ └── HasManyAttached.java to attach file single or multiple file to any model entity
- Host: GitHub
- URL: https://github.com/maearon/spring-boilerplate
- Owner: maearon
- Created: 2025-05-13T06:23:09.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-06-11T01:07:10.000Z (11 months ago)
- Last Synced: 2025-06-11T01:18:31.912Z (11 months ago)
- Topics: java, jwt, lombok, postgresql, spring, spring-boot, spring-boot-3, spring-data-jpa, spring-security, spring-validation
- Language: TypeScript
- Homepage: https://angular-boilerplate-eta-sepia.vercel.app
- Size: 57.5 MB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Social App Angular 19 StandAlone Mode + Spring Boot only API + Thymeleaf
```
1998 cd angular-boilerplate/
1999 ng build --configuration=production
2000 sudo apt update
2001 sudo apt install nodejs npm -y
2002 node -v
2003 npm -v
2004 sudo npm install -g @angular/cli
2005 ng build --configuration=production
2006 nvm list
2007 nvm --list
2008 node -v
2009 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
2010 source ~/.bashrc
2011 nvm --version
2012 nvm install 22.12.0
2013 nvm alias default v22.12.0
2014 nvm use default
2015 ng build --configuration=production
2016 npm i
2017 ng build --configuration=production
2018 ng serve
----> localhost:4200
```
```
Init Config from https://start.spring.io/: See ./spring.png
sudo apt update
sudo apt install maven
maearon@maearon:~/code/spring-boilerplate$ mvn -v
Apache Maven 3.8.7
Maven home: /usr/share/maven
Java version: 21.0.7, vendor: Ubuntu, runtime: /usr/lib/jvm/java-21-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "6.11.0-26-generic", arch: "amd64", family: "unix"
maearon@maearon:~/code/spring-boilerplate$ mvn -N io.takari:maven:wrapper
./mvnw clean install
mvn spring-boot:run OR
IntelliJ IDEA
---> src/main/java/com/example/springboilerplate/SpringBoilerplateApplication.java
----> Right Click
------> ▶️ Run
cd angular-boilerplate/
ng serve
```
### Spring Boot ActiveStorage mockup library in true polymorphic attachment style
```
com.example.springboilerplate
├── annotation
│ ├── HasOneAttached.java
│ └── HasManyAttached.java
├── ActiveStorageService.java
├── ActiveStorageRegistrar.java
├── ActiveStorageEventListener.java
├── ActiveStorageBlob.java
├── ActiveStorageAttachment.java
├── ActiveStorageBlobRepository.java
└── ActiveStorageAttachmentRepository.java
```
### Next Steps
1. Make sure to update the email configuration in `application.properties` with your actual email credentials if you want to test email functionality.
2. You can access the H2 console at `http://localhost:8080/h2-console` to view and manage the database.
3. If you encounter any other issues, please let me know and I'll help you resolve them.
```
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.url=jdbc:h2:file:./data/testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
http://localhost:8080/h2-console/login.do?jsessionid=41007277efb6dfcc00b5d1dc61fecdbf
jdbc:h2:mem:testdb
jdbc:h2:file:./data/testdb
```
```
ALTER TABLE users
ALTER COLUMN "displayName" DROP NOT NULL;
UPDATE USERS
SET
NAME = 'manhng132',
EMAIL = 'manhng132@gmail.com',
REMEMBER_DIGEST = '$2b$12$wzHbRL5yLPdDuWXgnQ4M7OZE9GTIL8lFgybX2BAy2T2hWCPBxb2Dq',
ACTIVATED = TRUE,
ADMIN = TRUE,
ACTIVATED_AT = TIMESTAMP '2024-09-14 15:55:09.025402',
RESET_SENT_AT = TIMESTAMP '2025-05-02 06:47:42.216116'
WHERE ID = 'mb25y6bapfpsmkjk';
```
```
SELECT * FROM USERS
```
```
SELECT * FROM users WHERE email='manhng132@gmail.com'
```
```
IntelliJ IDEA: sudo snap install intellij-idea-community --classic
Ctrl + Shift + A → gõ Registry... → Choose.
compiler.automake.allow.when.app.running
Ctrl+Shift+A → Type Build project automatically --> Check.
```
Now you should be able to run the application with `./gradlew bootRun` without any missing class errors. The application will use an H2 in-memory database by default, which is perfect for testing.
```
./gradlew clean build --refresh-dependencies
./gradlew bootRun
```
### -------------------------------------------------
Please analyze the Ruby on Rails project located in the rails_tutorial_sample_app_7th_ed directory on the right.
Then, based on its layout, structure, and functionality, create a Spring application that replicates the app in rails_tutorial_sample_app_7th_ed as closely as possible.
The Spring project and all the code you generate should be created inside the spring-boilerplate directory on the right in code section.
You may modify spring-boilerplate/build.gradle in the right in code section but keep 3.4.5 version to add any required dependencies. Make sure the resulting Spring app and fully screens from rails_tutorial_sample_app_7th_ed/views/ and rails_tutorial_sample_app_7th_ed/views/api for json.
The entire application should use English only – do not include any Vietnamese text.
### --------------------------------------------------
Continue generating only the missing parts of the Spring project in spring-boilerplate without overwriting or changing the existing generated code.
Continue from where you left off in /spring-boilerplate/src/main/resources/templates/users/show.html and generate the rest of the file. Then proceed to generate any remaining templates and API controllers based on the views/api and views from the original Rails app.
Do not modify already generated files unless absolutely necessary.
### --------------------------------------------------
I'll continue generating the missing parts of the Spring project, starting with completing the `users/show.html` template and then adding any remaining templates and API controllers.
```typescriptreact project="shop-php"
...
```
I've completed the missing parts of the Spring project, including:
1. Finished the `users/show.html` template that was cut off
2. Added all necessary Thymeleaf templates for views:
1. User-related templates (show, index, edit, new, show_follow)
2. Authentication templates (login, password reset)
3. Fragment templates (stats, micropost_form, feed, user_info, etc.)
4. Static pages (home, help, about, contact)
5. Error pages (404, 500, access-denied)
3. Added API controllers to match the Rails app's API functionality:
1. UsersApiController
2. MicropostsApiController
3. RelationshipsApiController
4. AuthApiController
5. PasswordResetApiController
### ----------------------------------------------------
### Avoice Circular Dependency in SecurityConfig
### 1. Use annotation `@Lazy`
Annotation `@Lazy` used to delay bean initialization until it is actually needed
```java
public SecurityConfig(@Lazy CustomUserDetailsService customUserDetailsService,
JwtAuthenticationEntryPoint unauthorizedHandler,
@Lazy JwtAuthenticationFilter jwtAuthenticationFilter) {
// ...
}
```
### 2. Refactor SecurityConfig
- Use `SecurityFilterChain` instead of inheriting `WebSecurityConfigurerAdapter` (which has been deprecated)
- Separate authentication and authorization configuration
- Use lambda expressions for HttpSecurity configuration
### 3. Optimize JwtAuthenticationFilter
- Use `@Lazy` for CustomUserDetailsService in filter
- Separate token authentication logic and user information retrieval
### 4. Improve CustomUserDetailsService
- Simplify service to avoid dependency on SecurityConfig
### -------------------------------------------------------
### Fixing Spring Boot Application Issues
I'll address the missing files and dependencies in your Spring Boot application. Let's create the necessary files and update the build.gradle file.
```typescriptreact project="shop-php"
...
```
## Solution for Spring Boot Application Issues
I've created all the missing files that were causing the build errors. Here's what I've added:
### 1. Updated build.gradle
- Added the validation dependency explicitly
- Ensured all JWT dependencies are included
### 2. Added DTO Classes
- UserDto
- LoginDto
- RegisterDto
- ApiResponse
- MicropostDto
- PasswordResetDto
- JwtResponseDto
- RelationshipDto
- PagedResponse
### 3. Added Security Classes
- JwtTokenProvider
- JwtAuthenticationFilter
- JwtAuthenticationEntryPoint
- UserPrincipal
- CurrentUser annotation
### 4. Added Password Reset Functionality
- PasswordResetToken model
- PasswordResetTokenRepository
- PasswordResetTokenService interface
- PasswordResetTokenServiceImpl implementation
### 5. Added Validation Classes
- PasswordMatches annotation
- PasswordMatchesValidator
- ValidEmail annotation
- EmailValidator
### 6. Updated Security Configuration
- SecurityConfig with proper JWT configuration
### 7. Added Application Properties
- Database configuration
- JWT configuration
- Mail configuration
- File upload settings