Changeset 140d098 for backend/src
- Timestamp:
- 02/09/26 20:20:12 (5 months ago)
- Branches:
- master
- Children:
- 3ebe47c
- Parents:
- 793ce2c
- Location:
- backend/src/main/java/com/trekr/backend
- Files:
-
- 14 added
- 1 edited
-
BackendApplication.java (modified) (2 diffs)
-
config/AuthProperties.java (added)
-
config/LegacyPasswordEncoder.java (added)
-
config/SecurityConfig.java (added)
-
controller/AuthController.java (added)
-
dto/auth/AuthResponse.java (added)
-
dto/auth/LoginRequest.java (added)
-
dto/auth/RegisterRequest.java (added)
-
entity/User.java (added)
-
exception/GlobalExceptionHandler.java (added)
-
repository/UserRepository.java (added)
-
resources/application.properties (added)
-
security/UserPrincipal.java (added)
-
service/AuthService.java (added)
-
service/JwtService.java (added)
Legend:
- Unmodified
- Added
- Removed
-
backend/src/main/java/com/trekr/backend/BackendApplication.java
r793ce2c r140d098 1 1 package com.trekr.backend; 2 2 3 import io.github.cdimascio.dotenv.Dotenv; 3 4 import org.springframework.boot.SpringApplication; 4 5 import org.springframework.boot.autoconfigure.SpringBootApplication; … … 8 9 9 10 public static void main(String[] args) { 10 SpringApplication.run(BackendApplication.class, args); 11 // Load .env file BEFORE Spring Boot starts 12 // This ensures system properties are available for ${} placeholder resolution 13 Dotenv dotenv = loadEnvironmentVariables(); 14 15 // Create SpringApplication instance 16 SpringApplication app = new SpringApplication(BackendApplication.class); 17 18 // Set system properties and default properties from .env file 19 if (dotenv != null) { 20 java.util.Map<String, Object> defaultProps = new java.util.HashMap<>(); 21 22 dotenv.entries().forEach(entry -> { 23 String key = entry.getKey(); 24 String value = entry.getValue(); 25 if (value != null && !value.trim().isEmpty()) { 26 // Set as system property (for ${} placeholders in application.properties) 27 System.setProperty(key, value); 28 // Collect for default properties 29 defaultProps.put(key, value); 30 } 31 }); 32 33 // Set all default properties at once 34 if (!defaultProps.isEmpty()) { 35 app.setDefaultProperties(defaultProps); 36 } 37 } 38 39 app.run(args); 40 } 41 42 private static Dotenv loadEnvironmentVariables() { 43 Dotenv dotenv = null; 44 try { 45 // Try current directory (backend/) 46 dotenv = Dotenv.configure() 47 .directory("./") 48 .ignoreIfMissing() 49 .load(); 50 } catch (Exception e) { 51 // Try parent directory if current doesn't work 52 try { 53 dotenv = Dotenv.configure() 54 .directory("../") 55 .ignoreIfMissing() 56 .load(); 57 } catch (Exception e2) { 58 System.err.println("WARNING: Could not load .env file. Make sure .env exists in backend/ directory."); 59 System.err.println("Error: " + e2.getMessage()); 60 return null; 61 } 62 } 63 64 // Verify critical properties are loaded 65 if (dotenv != null) { 66 String url = dotenv.get("SPRING_DATASOURCE_URL"); 67 String username = dotenv.get("SPRING_DATASOURCE_USERNAME"); 68 String password = dotenv.get("SPRING_DATASOURCE_PASSWORD"); 69 70 if (url != null && !url.trim().isEmpty()) { 71 System.out.println("✓ Database URL loaded from .env"); 72 } else { 73 System.err.println("✗ ERROR: SPRING_DATASOURCE_URL not found in .env file!"); 74 } 75 if (username != null && !username.trim().isEmpty()) { 76 System.out.println("✓ Database username loaded from .env"); 77 } else { 78 System.err.println("✗ ERROR: SPRING_DATASOURCE_USERNAME not found in .env file!"); 79 } 80 if (password != null && !password.trim().isEmpty()) { 81 System.out.println("✓ Database password loaded from .env"); 82 } else { 83 System.err.println("✗ ERROR: SPRING_DATASOURCE_PASSWORD not found in .env file!"); 84 } 85 } 86 87 return dotenv; 11 88 } 12 89
Note:
See TracChangeset
for help on using the changeset viewer.
