---修复callservice无法正常调用bug

This commit is contained in:
2025-10-23 10:32:46 +08:00
parent 4bacf06ecf
commit ce960feb01
10 changed files with 157 additions and 12 deletions

View File

@ -64,6 +64,19 @@
<version>${revision}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<!-- <exclusions>
排除JUnit 4引擎若存在
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions> -->
</dependency>
</dependencies>
<build>
<finalName>app</finalName>

View File

@ -0,0 +1,31 @@
package com.xjrsoft.config;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class AppConfig {
@Bean
public static BeanDefinitionRegistryPostProcessor allowCircularReferences() {
return new BeanDefinitionRegistryPostProcessor() {
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) {
// 不直接强转 registry而是在 postProcessBeanFactory 中操作 BeanFactory
}
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
// 此处的 beanFactory 一定是 ConfigurableListableBeanFactory 实例
((DefaultListableBeanFactory)beanFactory).setAllowCircularReferences(true);
}
};
}
}

View File

@ -0,0 +1,35 @@
package com.xjrsoft.module.test.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.xjrsoft.common.model.result.R;
import com.xjrsoft.module.common.db.service.CommonCallService;
import com.xjrsoft.module.dev.entity.Testfrom3;
import com.xjrsoft.module.dev.vo.Testfrom3Vo;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiOperation;
@RestController
@RequestMapping("/test/call")
public class CallTest {
// 注入待测试的服务
@Autowired
private CommonCallService callService;
@GetMapping(value = "/fSave")
@ApiOperation(value="根据id查询Testfrom3信息")
public R info(){
String out = callService.saveAfter("lng_b_price_term", 12);
System.out.println(out);
return R.ok(null);
}
}

View File

@ -0,0 +1,45 @@
spring:
cloud:
nacos: #nacos监控
config:
server-addr: 47.94.165.164:8848 # nacos 配置中心地址
namespace: ITC-MS
group: DNE
username: nacos
password: Lng@123
extension-configs:
- data-id: global-dev.yml
refresh: true
group: DNE
- data-id: discovery-dev.yml
refresh: true
group: DNE
- data-id: datasource-dev.yml
refresh: true
group: DNE
- data-id: seata-dev.yml
refresh: true
group: DNE
- data-id: redis-dev.yml
refresh: true
group: DNE
- data-id: magic-api.yml
refresh: true
group: DNE
- data-id: sa-token.yml
refresh: true
group: DNE
- data-id: camunda.yml
refresh: true
group: DNE
- data-id: sentinel-dev.yml
refresh: true
group: DNE

View File

@ -7,7 +7,7 @@ spring:
main:
allow-bean-definition-overriding: true
profiles:
active: dev
active: remote
cloud:
nacos: #nacos监控
config:

View File

@ -0,0 +1,25 @@
package com.xjrsoft;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.xjrsoft.module.common.db.service.CommonCallService;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ITCDemoApplication.class)
public class CallTest {
// 注入待测试的服务
@Autowired
private CommonCallService callService;
@Test
public void testCallSave() {
String out = callService.saveAfter("Ing_b_price_term", 12);
System.out.println(out);
}
}

View File

@ -7,7 +7,7 @@ spring:
main:
allow-bean-definition-overriding: true
profiles:
active: dev
active: remote
cloud:
nacos: #nacos监控
config: