Tuesday, September 22, 2015

Autowired not working for repository in spring boot

in spring boot, beside @SpringBootApplication, need to add the following 3 annotations to make @Autowired to init jpa repository objects.


@SpringBootApplication
@ComponentScan(basePackages = { "com.abc" })
@EnableJpaRepositories(basePackages = { "com.abc.repository" })
@EntityScan(basePackages = "com.abc.repository.entity")
public class WebApplication extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(WebApplication.class);
}

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

No comments:

Post a Comment