現在、私はSpringのロープを習っています。
私はautowireそうのようなメソッドのパラメータに試してみました:次のインタフェースとクラスで...アクセサメソッドがありません
@RequestMapping("/hello")
public String something(@Autowire AnInterface ai) {
ai.doSomething();
return "/";
}
:コントローラのメソッドを呼び出すとき
@Component
public interface AnInterface {
void doSomething();
}
@Component
public class Implementation implements AnInterface {
@Autowired private AnotherInterface ai;
public Implementation() { ; }
public Implementation(AnotherInterface ai) {
this.ai = ai;
}
public void setAi(AnotherInterface ai) {
this.ai = ai;
}
@Override
public void doSomething() {
System.out.println(ai.hello());
}
}
@Component
public interface AnotherInterface {
String hello();
}
@Component
public class AnotherImplementation implements AnotherInterface {
@Override
public String hello() {
return "hello";
}
}
はしかし、私はIllegalArgumentException
を得る:
Invoked method public abstract void AnInterface.doSomething() is no accessor method!
私は間違っていますか?事前に
感謝:)
あなたはこのコードを実行しましたが?コンパイル時エラーが発生すると思います。 – SachinSarawgi
ええ、それは私のために働く。 しかし、コードをコピーしているうちにエラーが発生した可能性があります。 エラーはどうなりますか? – portux