使用具体实现类来代替默认接口实现。例如:
@Configuration
public class MyConfig {
@Bean
public MyService myService() {
return new MyServiceImpl();
}
}
public interface MyService {
void doSomething();
}
public class MyServiceImpl implements MyService {
public void doSomething() {
// 实现方法
}
}
上述示例中,我们使用具体实现类MyServiceImpl来代替了默认接口实现,避免了The interface org.springframework.context.annotation.Bean defines default implementation for 'xxxx'的警告。这样可以保证配置的正确性,并提高代码的可读性和可维护性。