1. 程式人生 > >解決Spring+Quartz無法自動注入bean問題

解決Spring+Quartz無法自動注入bean問題

工作遇到的問題,使用Quartz定時任務,如果需要用到自動注入,會報空指標異常,看了原文博主的方法,只需要加上

SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);

就能正常注入了。

@Service
public class FIXDieMaintainAction implements Action {

	private static final long serialVersionUID = 5140977206344689587L;

	@Autowired
	private FIXDieMaintainService dieMaintainService;

	@Override
	public Object execute() throws Exception {
		// FIXDieMaintainService dieMaintainService = new FIXDieMaintainService();
		// dieMaintainService.autoCreateMaintain();
		SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(dieMaintainService);
		dieMaintainService.test();
		return null;
	}

}

相關推薦

解決Spring+Quartz無法自動注入bean問題

工作遇到的問題,使用Quartz定時任務,如果需要用到自動注入,會報空指標異常,看了原文博主的方法,只需要加上 SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this); 就能正常注

Spring Boot無法自動注入bean問題解決方案

前言:在使用Spring Boot+Mybatis時,寫完Mapper介面、Service、Controller後,啟動(圖1)打包專案(圖2)均失敗,提示無法自動注入bean。完成目標:1、無法自動注入bean錯誤資訊2、程式碼展示3、解決方案一、錯誤資訊:Descript

關於spring boot無法自動注入bean問題解決方案

. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_|

spring boot無法自動注入bean?原因在這兒

Description: Field helloSpringBootService in com.zd.hellospringboot.HelloController required a bean of type 'com.zd.service.HelloSpringBo

解決Spring中Quart無法自動注入Bean問題

        因專案需求,之前專案中已經有定時器的例子了,但是需求那邊過來的需求之前用的定時器並不能滿足,之前的定時器是用spring裡面的@Scheduled(cron = "0 0 0 * * ? ")這種方式,這是一種死的定時器,需求要的是動態定時器,使用者新增一個

在servlet中使用spring註解@Autowired自動注入bean

一,使用@Autowired注入需要使用的bean。    @Autowired     private  InstitutionService institutionService;          @Autowired     private UserService

解決Spring在某些條件下無法自動注入的問題

靜態工具類: package org.digdata.swustoj.util; import lombok.Getter; import lombok.NonNull; import org.sp

spring專案中quartz的job類不能自動注入bean的問題

在execute()方法中加入以下紅色部分程式碼://定時清除失效商品public class ClearInvalidGoodsJob implements Job {@Autowiredprivate GoodsInfoService goodsInfoservice;@

關於spring boot應用自動注入出現Consider defining a bean of type 'xxx' in your configuration問題解決方案

在做spring cloud的hystrix的時候,寫了一個controller,注入內部類時發生了一個錯誤:看起來就是找不到這個類,問題是我已經寫了這個類:百度後發現有發生同樣問題的童鞋,原來問題出在application類的註解@SpringBootApplication

解決spring 自動掃描包的時候出現 service無法自動注入的問題

遇到過這樣的問題,使用spring 將 包自動掃描進來在訪問的時候出現如下報錯: Error creating bean with name ‘com.xxx.demoController’: Injection of autowired depe

解決Spring+Quartz不能註入Bean的問題

package cep example www. trigger cal 不能 method prop Spring application-quartz的配置<?xml version="1.0" encoding="UTF-8"?><beans xml

Spring學習】spring註解自動注入bean

Spring mvc註解用到的配置: <!-- 啟用spring mvc 註解 --> <context:annotation-config /> <context:component-scan base-package

Spring在Thread中注入Bean無效的解決方式[嗡湯圓的小筆記]

在Spring專案中,有時需要新開執行緒完成一些複雜任務,而執行緒中可能需要注入一些服務。而通過Spring注入來管理和使用服務是較為合理的方式。但是若直接在Thread子類中通過註解方式注入Bean是無效的。 因為Spring本身預設Bean為單例模式構建,

SSH下使用Spring註解自動注入bean

首先匯入相關包:spring-beans-3.0.4.RELEASE.jar(org.springframework.beans.factory.annotation.Autowired用來注入bean)、spring-context-3.0.4.RELEASE.jar(o

分析解決 spring quartz 中出現的執行兩次問題

color src bat class 故事 重復 功能 fig 再次 1. 問題描述 在開發詢盤功能時,遇到一個需求,就是後臺定時任務執行用電施工業務的工單下發。 使用的技術是 spring quartz,因為其他應用有先例,配置quartz 完成後,先寫了一個 hell

SpringBoot 測試類無法自動注入@Autowired

原來的測試類的註解: @RunWith(SpringRunner.class) @SpringBootTest 一直沒法自動注入,後來在@SpringBootTest,加入啟動類Application後就可以了 @RunWith(SpringRunner.class) @Sp

spring抽象類中注入bean

在使用spring的時候,有時由於設計的需要,需要使用抽象類(比如模板方法模式),但在抽象類中實現方法是需要依賴其他的介面或類的方法,這時就需要對依賴的介面或類進行注入,需要注意以下內容: 在抽象類中需要注入(@autowire),在繼承了該抽象類的子類中同樣需要再次注入。比如當前專案中,使用者

Autofac 和 Quartz.Net 自動注入的整合

一:問題場景 在一次專案開發中,專案中已使用了Autofac.在新需求中要用到Quatrz.Net.在任務中使用注入方法,確始終無法使用注入的方法,經過千百次的度娘,終於找到了解決辦法!吐槽下度娘真心不好用~~~ 二:解決問題 1:需要下載Autofac的擴充套件包 https://github.com/al

淺談Spring框架,自動注入物件IoC/DI的過程(二)

在上一篇部落格中,我已經寫到怎麼用自動注入的物件了。可能我說的不是太清楚,有些朋友還不是很明白,那麼這次我們結合service層呼叫DAO層的方法,再詳細說說怎麼隨心所欲的使用物件。 先看一下程式碼:

解決Spring Boot產生環形注入的問題

*************************** APPLICATION FAILED TO START *************************** Description: The dependencies of some of the beans i