修改了启动模式

This commit is contained in:
zhengsl 2026-01-05 16:52:03 +08:00
parent 9be237c53e
commit f3c4056c1e
4 changed files with 60 additions and 28 deletions

1
.vscode/launch.json vendored
View File

@ -7,7 +7,6 @@
"hostName": "localhost", "hostName": "localhost",
"port": "5005" "port": "5005"
}, },
java
{ {
"type": "java", "type": "java",
"name": "CriticalScenarioApplication", "name": "CriticalScenarioApplication",

View File

@ -51,6 +51,23 @@
4. 增加 OpenAPI 文档与前端集成接口规范。 4. 增加 OpenAPI 文档与前端集成接口规范。
5. 引入结果持久化与查询报表。 5. 引入结果持久化与查询报表。
## 调试与开发指南
### Maven 命令行启动 + 远程调试
如果您偏好使用命令行启动,或者需要模拟特定的 Maven 环境,可采用以下方式:
1. **启动应用**
在终端中运行以下命令,该命令会以调试模式启动应用并监听 `5005` 端口(`suspend=n` 表示不等待调试器连接直接启动,如需等待可改为 `y`)。
> 注意PowerShell 中需要使用单引号包裹 JVM 参数,防止解析错误。
```bash
mvn -DskipTests spring-boot:run -pl business-css '-Dspring-boot.run.jvmArguments=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005'
```
2. **附加调试器**
应用启动后,转到 IDE 的 "运行和调试" (Run and Debug) 面板,选择 **"Attach to Remote Program5005"** 配置(需确保 `.vscode/launch.json` 中已存在相应配置然后点击运行。IDE 将连接到正在运行的 Maven 进程,即可开始断点调试。
## 运维与配置 ## 运维与配置
- 端口默认 `8082`,环境覆盖通过 `application.yml` 与外部化配置。 - 端口默认 `8082`,环境覆盖通过 `application.yml` 与外部化配置。
- 数据库连接按环境注入dev/test/prod - 数据库连接按环境注入dev/test/prod

View File

@ -64,7 +64,14 @@
<artifactId>platform</artifactId> <artifactId>platform</artifactId>
<version>1.0</version> <version>1.0</version>
<classifier>plain</classifier> <classifier>plain</classifier>
</dependency> </dependency>
<!-- 显式添加 MyBatis-Plus 依赖,确保测试环境类加载正确 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.6</version>
</dependency>
<!-- Lombok --> <!-- Lombok -->

View File

@ -4,6 +4,7 @@ import com.yfd.platform.config.bean.LoginProperties;
import com.yfd.platform.exception.AccessDeniedHandExcetion; import com.yfd.platform.exception.AccessDeniedHandExcetion;
import com.yfd.platform.exception.AuthenticationException; import com.yfd.platform.exception.AuthenticationException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -19,7 +20,10 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
@Configuration @Configuration
public class SecurityConfig { public class SecurityConfig {
// 1. 注入配置项默认为 false
@Value("${security.dev.permit:false}")
private boolean devPermit;
@Bean @Bean
public PasswordEncoder passwordEncoder() { public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder(); return new BCryptPasswordEncoder();
@ -50,31 +54,36 @@ public class SecurityConfig {
http http
.csrf(csrf -> csrf.disable()) .csrf(csrf -> csrf.disable())
.sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) .sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(auth -> auth .authorizeHttpRequests(auth -> {
.requestMatchers("/user/login").anonymous() // 如果配置为 true则允许所有请求
.requestMatchers("/user/code").permitAll() if (devPermit) {
.requestMatchers(HttpMethod.GET, auth.anyRequest().permitAll();
"/*.html", } else {
"/webSocket/**", auth.requestMatchers("/user/login").anonymous()
"/assets/**", .requestMatchers("/user/code").permitAll()
"/icon/**").permitAll() .requestMatchers(HttpMethod.GET,
.requestMatchers( "/*.html",
"/swagger-ui.html", "/webSocket/**",
"/swagger-ui/**", "/assets/**",
"/v3/api-docs/**", "/icon/**").permitAll()
"/v3/api-docs.yaml", .requestMatchers(
"/swagger-resources/**", "/swagger-ui.html",
"/webjars/**", "/swagger-ui/**",
"/*/api-docs").permitAll() "/v3/api-docs/**",
.requestMatchers( "/v3/api-docs.yaml",
"/report/**", "/swagger-resources/**",
"/images/**", "/webjars/**",
"/pageimage/**", "/*/api-docs").permitAll()
"/avatar/**", .requestMatchers(
"/systemurl/**", "/report/**",
"/api/imageserver/upload").permitAll() "/images/**",
.anyRequest().authenticated() "/pageimage/**",
) "/avatar/**",
"/systemurl/**",
"/api/imageserver/upload").permitAll()
.anyRequest().authenticated();
}
})
.cors(cors -> {}); .cors(cors -> {});
http.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class); http.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);