|
17 | 17 | import org.springframework.transaction.PlatformTransactionManager; |
18 | 18 | import org.springframework.transaction.annotation.EnableTransactionManagement; |
19 | 19 |
|
| 20 | +import java.util.Map; |
| 21 | + |
20 | 22 | import javax.sql.DataSource; |
21 | 23 |
|
| 24 | +import com.phantoms.phantomsbackend.pojo.entity.primary.AuthUser; |
| 25 | +import com.phantoms.phantomsbackend.pojo.entity.primary.onebot.ChatRecord; |
| 26 | +import com.phantoms.phantomsbackend.pojo.entity.primary.ExpeditionaryTeam; |
| 27 | +import com.phantoms.phantomsbackend.pojo.entity.primary.Image; |
| 28 | +import com.phantoms.phantomsbackend.pojo.entity.primary.Message; |
| 29 | +import com.phantoms.phantomsbackend.pojo.entity.primary.Password; |
| 30 | +import com.phantoms.phantomsbackend.pojo.entity.primary.Recruitment; |
| 31 | +import com.phantoms.phantomsbackend.pojo.entity.primary.SystemConfig; |
| 32 | +import com.phantoms.phantomsbackend.pojo.entity.primary.User; |
| 33 | +import com.phantoms.phantomsbackend.pojo.entity.primary.onebot.UserMessage; |
| 34 | +import com.phantoms.phantomsbackend.pojo.entity.primary.UserProfile; |
| 35 | + |
22 | 36 | @Configuration |
23 | 37 | @EnableTransactionManagement |
24 | 38 | @EnableJpaRepositories( |
@@ -94,10 +108,34 @@ public DataSource primaryDataSource() { |
94 | 108 | @Bean(name = "primaryEntityManagerFactory") |
95 | 109 | public LocalContainerEntityManagerFactoryBean primaryEntityManagerFactory( |
96 | 110 | EntityManagerFactoryBuilder builder, @Qualifier("primaryDataSource") DataSource dataSource) { |
| 111 | + Map<String, Object> properties = new java.util.HashMap<>(); |
| 112 | + // 优化内存配置:关闭所有不必要的扫描和缓存 |
| 113 | + properties.put("hibernate.archive.autodetection", "none"); // 完全关闭归档自动检测 |
| 114 | + properties.put("hibernate.javax.persistence.validation.mode", "none"); // 关闭Bean Validation |
| 115 | + properties.put("hibernate.cache.use_second_level_cache", "false"); |
| 116 | + properties.put("hibernate.cache.use_query_cache", "false"); |
| 117 | + properties.put("hibernate.generate_statistics", "false"); |
| 118 | + properties.put("hibernate.auto_quote_keyword", "false"); |
| 119 | + |
97 | 120 | return builder |
98 | 121 | .dataSource(dataSource) |
99 | | - .packages("com.phantoms.phantomsbackend.pojo.entity.primary") |
| 122 | + // .packages("com.phantoms.phantomsbackend.pojo.entity.primary") |
100 | 123 | .persistenceUnit("primary") |
| 124 | + .properties(properties) |
| 125 | + // 显式指定实体类,避免扫描整个JAR文件 |
| 126 | + .packages( |
| 127 | + AuthUser.class, |
| 128 | + ChatRecord.class, |
| 129 | + ExpeditionaryTeam.class, |
| 130 | + Image.class, |
| 131 | + Message.class, |
| 132 | + Password.class, |
| 133 | + Recruitment.class, |
| 134 | + SystemConfig.class, |
| 135 | + User.class, |
| 136 | + UserMessage.class, |
| 137 | + UserProfile.class |
| 138 | + ) |
101 | 139 | .build(); |
102 | 140 | } |
103 | 141 |
|
|
0 commit comments