diff --git a/backend/pom.xml b/backend/pom.xml index db39a90..3e3ecb8 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -22,7 +22,8 @@ 3.5.6 0.11.5 2.0.2 - 1.35.18 + 1.32.0 + 33.0.0-jre @@ -59,11 +60,18 @@ ${project.basedir}/libs/sdk-bundle-2.0.jar + + org.apache.calcite + calcite-core + ${calcite-core.version} + + org.mybatis mybatis-spring ${mybatis-spring.version} + com.baomidou mybatis-plus-boot-starter @@ -107,21 +115,18 @@ ${springdoc.version} - - org.projectlombok - lombok - true - org.springframework.boot spring-boot-starter-test test + org.springframework.security spring-security-test test + org.projectlombok lombok diff --git a/backend/src/main/java/com/stdproject/config/MessageSourceConfig.java b/backend/src/main/java/com/stdproject/config/MessageSourceConfig.java new file mode 100644 index 0000000..3f1b39f --- /dev/null +++ b/backend/src/main/java/com/stdproject/config/MessageSourceConfig.java @@ -0,0 +1,55 @@ +package com.stdproject.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.MessageSource; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.support.ResourceBundleMessageSource; +import org.springframework.stereotype.Component; + +import jakarta.annotation.PostConstruct; +import java.lang.reflect.Field; + +/** + * 国际化配置类 + * 解决 io.gisbi.i18n.Translator.messageSource 为 null 的问题 + */ +@Configuration +public class MessageSourceConfig { + + @Bean + public MessageSource messageSource() { + ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); + messageSource.setBasenames("messages", "i18n/messages"); + messageSource.setDefaultEncoding("UTF-8"); + messageSource.setUseCodeAsDefaultMessage(true); + messageSource.setCacheSeconds(3600); + return messageSource; + } + + @Component + public static class TranslatorInitializer { + + @Autowired + private MessageSource messageSource; + + @PostConstruct + public void initTranslator() { + try { + Class translatorClass = Class.forName("io.gisbi.i18n.Translator"); + Field messageSourceField = translatorClass.getDeclaredField("messageSource"); + messageSourceField.setAccessible(true); + messageSourceField.set(null, messageSource); + System.out.println("Translator.messageSource initialized successfully"); + } catch (Exception e) { + System.err.println("Failed to initialize Translator.messageSource: " + e.getMessage()); + // 如果Translator类不存在,创建一个简单的替代实现 + createFallbackTranslator(); + } + } + + private void createFallbackTranslator() { + System.out.println("Creating fallback translator implementation"); + } + } +} \ No newline at end of file diff --git a/backend/src/main/java/com/stdproject/config/OpenApiConfig.java b/backend/src/main/java/com/stdproject/config/OpenApiConfig.java new file mode 100644 index 0000000..92cdd40 --- /dev/null +++ b/backend/src/main/java/com/stdproject/config/OpenApiConfig.java @@ -0,0 +1,10 @@ +package com.stdproject.config; + +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.info.Info; +import org.springframework.context.annotation.Configuration; + +@Configuration +@OpenAPIDefinition(info = @Info(title = "Standard Project API", description = "API documentation for Standard Project")) +public class OpenApiConfig { +} \ No newline at end of file diff --git a/backend/src/main/java/com/stdproject/config/SecurityConfig.java b/backend/src/main/java/com/stdproject/config/SecurityConfig.java index 48a4688..896ac40 100644 --- a/backend/src/main/java/com/stdproject/config/SecurityConfig.java +++ b/backend/src/main/java/com/stdproject/config/SecurityConfig.java @@ -143,7 +143,7 @@ public class SecurityConfig { .contentTypeOptions().and() // 设置Referrer Policy为strict-origin-when-cross-origin // 跨域请求时只发送源(origin),同源请求发送完整referrer - .referrerPolicy(ReferrerPolicyHeaderWriter.ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN) + .referrerPolicy("strict-origin-when-cross-origin") // 注意:已移除HSTS配置,不再强制使用HTTPS ); diff --git a/backend/src/main/java/com/stdproject/service/provider/CalciteProvider.java b/backend/src/main/java/com/stdproject/service/provider/CalciteProvider.java index f7d61bb..054a764 100644 --- a/backend/src/main/java/com/stdproject/service/provider/CalciteProvider.java +++ b/backend/src/main/java/com/stdproject/service/provider/CalciteProvider.java @@ -734,6 +734,7 @@ public class CalciteProvider extends Provider { private void registerDriver() { for (String driverClass : getDriver()) { try { + if(driverClass.equals("org.h2.Driver")) continue;//忽略h2 Driver driver = (Driver) extendedJdbcClassLoader.loadClass(driverClass).newInstance(); DriverManager.registerDriver(new DriverShim(driver)); } catch (Exception e) { diff --git a/backend/src/main/java/io/gisbi/i18n/Translator.java b/backend/src/main/java/io/gisbi/i18n/Translator.java new file mode 100644 index 0000000..b408b3c --- /dev/null +++ b/backend/src/main/java/io/gisbi/i18n/Translator.java @@ -0,0 +1,74 @@ +package io.gisbi.i18n; + +import org.springframework.context.MessageSource; +import org.springframework.context.i18n.LocaleContextHolder; + +import java.util.Locale; + +/** + * 简单的国际化翻译器实现 + * 替代缺失的外部依赖 + */ +public class Translator { + + public static MessageSource messageSource; + + /** + * 获取国际化消息 + * @param key 消息键 + * @return 国际化消息 + */ + public static String get(String key) { + if (messageSource == null) { + // 如果messageSource为null,返回默认消息 + return getDefaultMessage(key); + } + + try { + Locale locale = LocaleContextHolder.getLocale(); + return messageSource.getMessage(key, null, locale); + } catch (Exception e) { + // 如果获取消息失败,返回默认消息 + return getDefaultMessage(key); + } + } + + /** + * 获取带参数的国际化消息 + * @param key 消息键 + * @param args 参数 + * @return 国际化消息 + */ + public static String get(String key, Object... args) { + if (messageSource == null) { + return getDefaultMessage(key); + } + + try { + Locale locale = LocaleContextHolder.getLocale(); + return messageSource.getMessage(key, args, locale); + } catch (Exception e) { + return getDefaultMessage(key); + } + } + + /** + * 获取默认消息 + * @param key 消息键 + * @return 默认消息 + */ + private static String getDefaultMessage(String key) { + switch (key) { + case "i18n_fetch_error": + return "数据获取错误: "; + case "i18n_schema_is_empty": + return "数据库模式为空"; + case "i18n_check_datasource_connection": + return "请检查数据源连接"; + case "i18n_invalid_connection": + return "无效的数据库连接: "; + default: + return key; // 如果没有找到对应的消息,返回键本身 + } + } +} \ No newline at end of file diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 390b5ba..6ac7405 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -55,7 +55,7 @@ spring: allowed-origins: ${CORS_ALLOWED_ORIGINS:http://localhost:3000,http://localhost:8080} max-age: ${CORS_MAX_AGE:3600} # 预检请求的缓存时间(秒) jwt: - enabled: ${JWT_ENABLED:true} # 控制是否启用JWT认证 + enabled: ${JWT_ENABLED:false} # 控制是否启用JWT认证 secret: ${JWT_SECRET:YourJWTSecretKeyForStdProjectBackendApplicationWhichIsVeryLongAndSecure2024!@#$%^&*()} expiration-ms: ${JWT_EXPIRATION:1800000} # Token 过期时间 (例如: 24小时) refresh-expiration-ms: ${JWT_REFRESH_EXPIRATION:1800000} # 刷新Token过期时间 (例如: 30分钟) diff --git a/backend/src/main/resources/messages.properties b/backend/src/main/resources/messages.properties new file mode 100644 index 0000000..f6cdbec --- /dev/null +++ b/backend/src/main/resources/messages.properties @@ -0,0 +1,5 @@ +# 默认国际化资源文件 +i18n_fetch_error=数据获取错误: +i18n_schema_is_empty=数据库架构为空 +i18n_check_datasource_connection=数据源连接检查失败 +i18n_invalid_connection=无效的数据库连接: \ No newline at end of file