fix: 修复服务启动配置问题

- 所有业务服务添加scanBasePackages扫描fund-common
- Gateway添加ReactiveRedisConfig提供ReactiveRedisTemplate
- Gateway排除Servlet相关类和RedisService(需要非响应式RedisTemplate)
- 解决Bean名称冲突(ReactiveRedisConfig)
This commit is contained in:
zhangjf 2026-02-20 17:53:12 +08:00
parent a6716da742
commit ef46844bfd
7 changed files with 60 additions and 6 deletions

View File

@ -4,7 +4,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication @SpringBootApplication(scanBasePackages = {"com.fundplatform.exp", "com.fundplatform.common"})
@EnableDiscoveryClient @EnableDiscoveryClient
public class ExpApplication { public class ExpApplication {

View File

@ -4,7 +4,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication @SpringBootApplication(scanBasePackages = {"com.fundplatform.file", "com.fundplatform.common"})
@EnableDiscoveryClient @EnableDiscoveryClient
public class FileApplication { public class FileApplication {

View File

@ -2,8 +2,18 @@ package com.fundplatform.gateway;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication @SpringBootApplication(scanBasePackages = {
"com.fundplatform.gateway",
"com.fundplatform.common.auth", // TokenInfo
"com.fundplatform.common.context", // TraceContextHolder
"com.fundplatform.common.exception", // GlobalExceptionHandler
"com.fundplatform.common.result" // Result class
// 注意不扫描 common.cache (需要RedisTemplateGateway只有ReactiveRedisTemplate)
// 注意不扫描 common.web (使用Servlet APIGateway是WebFlux)
})
@EnableDiscoveryClient
public class GatewayApplication { public class GatewayApplication {
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -0,0 +1,44 @@
package com.fundplatform.gateway.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* Redis配置类
* 为Gateway提供ReactiveRedisTemplate
*/
@Configuration
public class ReactiveRedisConfig {
@Bean
public ReactiveRedisTemplate<String, Object> reactiveRedisTemplate(
ReactiveRedisConnectionFactory connectionFactory) {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
objectMapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance,
ObjectMapper.DefaultTyping.NON_FINAL);
Jackson2JsonRedisSerializer<Object> jsonSerializer = new Jackson2JsonRedisSerializer<>(objectMapper, Object.class);
StringRedisSerializer stringSerializer = StringRedisSerializer.UTF_8;
RedisSerializationContext<String, Object> serializationContext = RedisSerializationContext
.<String, Object>newSerializationContext()
.key(stringSerializer)
.value(jsonSerializer)
.hashKey(stringSerializer)
.hashValue(jsonSerializer)
.build();
return new ReactiveRedisTemplate<>(connectionFactory, serializationContext);
}
}

View File

@ -5,7 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication @SpringBootApplication(scanBasePackages = {"com.fundplatform.receipt", "com.fundplatform.common"})
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableScheduling @EnableScheduling
public class ReceiptApplication { public class ReceiptApplication {

View File

@ -4,7 +4,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication @SpringBootApplication(scanBasePackages = {"com.fundplatform.req", "com.fundplatform.common"})
@EnableDiscoveryClient @EnableDiscoveryClient
public class ReqApplication { public class ReqApplication {

View File

@ -8,7 +8,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/** /**
* 系统服务启动类 * 系统服务启动类
*/ */
@SpringBootApplication @SpringBootApplication(scanBasePackages = {"com.fundplatform.sys", "com.fundplatform.common"})
@EnableDiscoveryClient @EnableDiscoveryClient
@MapperScan("com.fundplatform.sys.data.mapper") @MapperScan("com.fundplatform.sys.data.mapper")
public class SysApplication { public class SysApplication {