「Spring入門」interfaceと@Serviceの使い方

1.インタフェース
public interface Filter {
public String doFilter(String param);
}

2.インタフェースを実現するクラス
public class TimeFilter implements Filter {

@Override
public String doFilter(String param) {
return param.replace(“beijing", “shanghai");
}

}

3. @Service(“timeFilter")の設定
import org.springframework.stereotype.Service;
@Service(“timeFilter")
public class TimeFilter implements Filter {

@Override
public String doFilter(String param) {
return param.replace(“beijing", “shanghai");
}

}

4.Injection
@Autowired
@Qualifier(“timeFilter")
Filter timeFilter;

Java

Posted by arkgame