2016-08-30 5 views
2

私はSpring Bootの新機能です。Spring Boot:CommandLineRunnerのインスタンスを多く渡すのは安全ですか?

@SpringBootApplication(exclude = JpaRepositoriesAutoConfiguration.class) 
public class Application { 

    private static final Logger log = LoggerFactory.getLogger(Application.class); 

    ... 

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

    @Bean 
    public CommandLineRunner App(DBReportRepository dbReportRepository, 
            ClientRepository clientRepository, FileParser fileParser, 
             MessagingService messagingService, ClientReportFactoryImpl clientReportFactory) ... 

私は思っていたことがCommandLineRunnerに(クラスを注釈付き@Servicesある)ので、多くのパラメータを渡すことをお勧めです:私は、私はいくつかのコードを持っているApplication.javaクラスが持っています。

また、私はSpring Bootをあまりにも多く作成していますが、Spring Bootにこれらの@Servicesクラスを認識させる別の方法があります。

答えて

0

私の春のブート設定には、AppConfigクラスが欠落していました。それがなければ@Computersクラスや@Serviceクラスで@Autowiredを使うことができ、CommandLineRunnerに引数として渡されました。私はこのように見ているAppConfig.javaを作成しました:

@Configuration 
@ComponentScan(basePackages = "your.main.package") 
public class AppConfig { 
} 

を、その後、私は@Autowired どこでも可能性を使用することができます。

関連する問題