spring项目普通类引入service为空的解决办法

1、初始化本类的方法
//例:
@Component
public class PushCallback3 implements MqttCallback {
public static PushCallback3 impMqttCallback1;
@Autowired
private T_moveService tmoveService;

@PostConstruct
public void init() {
	impMqttCallback1 = this;
	impMqttCallback1.tmoveService=this.tmoveService;
	  
}

//调用时使用
impMqttCallback1.queryBymove_number(number);
}
2、如果第一种方法无法使用,可采用重新加载xml的方式,加载你需要的类
//例:

public static ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/spring-*.xml");
private static T_moveService systemalarmService = (T_moveService)applicationContext.getBean(T_moveService.class);

//调用时使用
T_moveService .queryBymove_number(number);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot和Spring Cloud是两个相互补充的框架,可以一起使用来开发分布式系统。 首先,你需要在Spring Boot项目引入Spring Cloud的依赖。在项目的pom.xml文件添加以下依赖: ```xml <dependencies> <!-- Spring Boot 核心依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <!-- Spring Cloud 相关依赖 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <!-- 其他Spring Cloud组件的依赖 --> <!-- ... --> </dependencies> ``` 接下来,你可以使用Spring Cloud提供的各种组件来实现分布式系统的功能,例如服务注册与发现、负载均衡、断路器等。常用的组件包括Eureka、Ribbon、Feign、Hystrix等。 以服务注册与发现为例,你可以在Spring Boot项目创建一个Eureka Server,用于服务的注册和发现。在主启动上添加`@EnableEurekaServer`注解,启用Eureka Server功能。 ```java @SpringBootApplication @EnableEurekaServer public class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); } } ``` 另外,你还可以创建一个普通Spring Boot服务,并将其注册到Eureka Server上。在这个服务的配置文件,添加以下配置: ```yaml spring: application: name: your-service-name # 服务名称,用于注册到Eureka Server eureka: client: service-url: defaultZone: http://localhost:8761/eureka/ # Eureka Server的地址 ``` 这样,你就完成了Spring Boot与Spring Cloud的整合,实现了服务的注册与发现功能。你可以继续探索Spring Cloud的其他组件,根据需求选择合适的组件进行整合。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值