アプリ版:「スタンプのみでお礼する」機能のリリースについて

spring 超初心者です。cloudfoundyでcronを実行しようとしています。

CronService から@Autowiredで、StartJob_cを呼び出し
更に呼び出されたStartJob_cから、@AutowiredでReadFile_cを呼び出そうとしています。

しかし、Injection of autowired dependencies failed; nested exception
というエラーが出て動きません。

質問1)このような、呼び出しはできないのでしょうか?
質問2)springでこのような、呼び出しをしたい場合、どうするのが良いのでしょうか?




エラー内容は、
[ERROR] [main 11:08:03] (ContextLoader.java:initWebApplicationContext:220) Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cronService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.krams.tutorial.job.StartJob org.krams.tutorial.job.CronService.startJob; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'syncStartJob': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.krams.tutorial.job.ReadFile org.krams.tutorial.job.StartJob_c.readFile_cService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.krams.tutorial.job.ReadFile] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

です。


ロジックサンプルは、以下の通りです。

@Service
public class CronService implements Cron{

protected static Logger logger = Logger.getLogger("service");

@Autowired
@Qualifier("syncStartJob")
private StartJob startJob;

@Scheduled(cron="*/10 * * * * ?")
public void doSchedule() {
logger.debug("cron");
startJob.jobExec();

}
}




@Component("syncStartJob")
public class StartJob_c implements StartJob{
protected static Logger logger = Logger.getLogger("service");

//@Autowired
//private StartJob2 startJob2_cService;

@Autowired
private ReadFile readFile_cService;
@Autowired
private DeleteFile deleteFile_cService;
@Autowired
private ShinchokuFile1LineDel shinchokuFile1LineDel_cService;

public void jobExec() {
// TODO Auto-generated method stub
logger.debug("StartJob");

List<String> strYMDStartArray = new ArrayList();
strYMDStartArray.add("20060701");//0 1
strYMDStartArray.add("20060501");//1 2
strYMDStartArray.add("20060301");//2 3
strYMDStartArray.add("20060101");//3 4
strYMDStartArray.add("20051101");//4 5
strYMDStartArray.add("20050901");//5 6

String strFileName = "";


List<Integer> AYMDCNTData = new ArrayList();
strFileName = "YMDCNT";
AYMDCNTData = this.readFile_cService.readIntData(strFileName);
int intYMDCNT = AYMDCNTData.size();



List<Integer> ACNTData = new ArrayList();
strFileName = "JobCNT";
ACNTData = this.readFile_cService.readIntData(strFileName);
int intJobCNT = ACNTData.size();




String strYMDStart = "";
String strYMDEnd = "";
int intYMDID = 0;
int intJobCounter = 11;
intJobCounter = intJobCounter + intJobCNT;

String sTrailJoken_start = "";
String sTrailJoken_end = "";
String sTrailGaku_start = "";
String sTrailGaku_end = "";

if( intJobCounter == 11){
sTrailJoken_start = "10";
sTrailJoken_end = "10";
sTrailGaku_start = "5000";
sTrailGaku_end = "5000";
}else if(intJobCounter == 12){
sTrailJoken_start = "10";
sTrailJoken_end = "10";
sTrailGaku_start = "10000";
sTrailGaku_end = "10000";
}else if(intJobCounter == 13){
sTrailJoken_start = "10";
sTrailJoken_end = "10";
sTrailGaku_start = "15000";
sTrailGaku_end = "15000";
}else if(intJobCounter == 14){
sTrailJoken_start = "10";
sTrailJoken_end = "10";
sTrailGaku_start = "20000";
sTrailGaku_end = "20000";
}

A 回答 (1件)

例外のログはこれだけじゃないですよね?

    • good
    • 2
この回答へのお礼

回答ありがとうございます。

今日、もう一度プログラムを見直したところ、呼び出される側の
ReadFile_c
に、@Serviceを付け忘れていることがわかりました。

という事で、解決いたしました。

ありがとうございました。

今後ともよろしくお願いします。

お礼日時:2011/08/19 22:47

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!