义齿mooc.house.biz.service.XXX' in your config

2038 ワード

エラー:
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.2018-05-10 19:59:57.321 ERROR 8692 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : ***************************APPLICATION FAILED TO START***************************Description:Field userService in com.mooc.house.web.controller.UserController required a bean of type 'com.mooc.house.biz.service.UserService' that could not be found.Action:Consider defining a bean of type 'com.mooc.house.biz.service.UserService' in your configuration.
コンソールで印刷されたヒントは、構成中に自動注入タイプを指定するbeanが見つからないことであり、多方面にわたって調べた結果、通常@Component注釈を加えたクラスは自動的にSpringスキャンされて生成Beanにspringコンテナに登録され、見つからなかったと言った以上、この注釈がspringに認識されていないという結論に達した.問題の核心はアプリケーションクラスの注釈SpringBootApplicationにある.
この注記は、実際には次のような注釈の山の効果に相当します.1つの注記は@Componentです.デフォルトでは、コントローラと同じパッケージとそのサブパッケージの下にある@Component注記のみをスキャンし、指定した注釈のクラスをBeanに自動的に登録できる@Service@Controllerと@Repository
@SpringBootConfiguration@EnableAutoConfiguration@ComponentScan(excludeFilters={@Filter(type=CUSTOM, classes={TypeExcludeFilter.class}), @Filter(type=CUSTOM, classes={AutoConfigurationExcludeFilter.class})})@Target(value={TYPE})@Retention(value=RUNTIME)@Documented
@Inherited
次のソリューション:
2つの解決策:1.インタフェースと対応する実装クラスをアプリケーション起動クラスと同じディレクトリまたは彼のサブディレクトリの下に配置すると、注釈がスキャンされ、最も手間が省ける方法です.
  2 .指定したアプリケーションクラスにこのような注釈を追加し、アプリケーションクラスがスキャンするパッケージの注釈を手動で指定します.次のようにします.
@SpringBootApplication
@ComponentScan(basePackages = " ")

public class HouseWebApplication {

   public static void main(String[] args) {
      SpringApplication.run(HouseWebApplication.class, args);
   }
}