더북(TheBook)

각설하고, 코드로 가서 스프링 애너테이션 설정을 사용하려면 무엇을 변경해야 하는지 살펴보자(예제 3-9 참고).

 예제 3-9 AnnotatedSearchEngine.java

package com.apress.isf.spring.annotated.service;

 

import java.util.ArrayList;

import java.util.Arrays;

import java.util.List;

 

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

 

import com.apress.isf.java.model.Document;

import com.apress.isf.java.model.Type;

import com.apress.isf.java.service.SearchEngine;

import com.apress.isf.spring.data.DocumentDAO;

 

@Service("engine")

public class AnnotatedSearchEngine implements SearchEngine {

 

@Autowired

private DocumentDAO documentDAO;

 

public List<Document> findByType(Type documentType) {

List<Document> result = new ArrayList<Document>();

for (Document doc : listAll()) {

if (doc.getType().getName().equals(documentType.getName()))

result.add(doc);

}

return result;

}

 

public List<Document> listAll() {

return Arrays.asList(documentDAO.getAll());

}

 

}


신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.