component-scan

Spring Boot: autowire beans from library project

ⅰ亾dé卋堺 提交于 2020-04-05 09:11:31
问题 I'm struggling to autowire beans from my custom library, imported with gradle. after reading couple of similar topics I am still unable to find solution. I have Spring Boot project that depends on other project(my custom library with Components, Repositories etc...). This library is a Spring non-runnable jar, that consists primarily from domain Entities and Repositories. It doesn't have runnable Application.class and any properties... When I starting the application I can see that My

Spring boot component scan include a single class [duplicate]

耗尽温柔 提交于 2020-02-21 10:35:46
问题 This question already has answers here : Using @ComponentScan or <context:component-scan /> with only one class (4 answers) Closed 2 years ago . I am using spring component scan to auto detect beans as: @ComponentScan({"com.org.x, com.org.y"}) The issue is I want all classes in com.org.x to be scanned but I want a single class, com.org.y.SomeService.class , alone to be scanned from com.org.y How can I achieve this ? Also apart from using context scan, how can I created this bean and inject in

@ComponentScan with multiple configuration class : Annotation Based Configuration

╄→尐↘猪︶ㄣ 提交于 2020-01-31 03:41:11
问题 As per Spring Doc- Configures component scanning directives for use with @Configuration classes. Provides support parallel with Spring XML's <context:component-scan> element. In my spring web application there are multiple files those are marked @Configuration ,in order to register @component bean in spring container- Question1- Can we use @ComponentScan in any of the @Configuration class or in all @Configuration classes? Question2- Also I seen in spring doc @Configuration @ComponentScan

How to configure controller in spring without component scanning in xml?

情到浓时终转凉″ 提交于 2020-01-23 13:52:10
问题 I have to design a very large scale project for a bank using spring mvc. I already choose to go with the XML configuration. My concern is to limit the start up time of the server. There will be approximately 2000 controllers. I already use component scan for scanning the @Controller . It worked fine. But, the problem is when I remove the component scan from XML and add the controller bean using bean configuration manually in XML, it didn't create the instance of controller in IOC container.

How to configure controller in spring without component scanning in xml?

放肆的年华 提交于 2020-01-23 13:51:51
问题 I have to design a very large scale project for a bank using spring mvc. I already choose to go with the XML configuration. My concern is to limit the start up time of the server. There will be approximately 2000 controllers. I already use component scan for scanning the @Controller . It worked fine. But, the problem is when I remove the component scan from XML and add the controller bean using bean configuration manually in XML, it didn't create the instance of controller in IOC container.

getServletConfigClasses() vs getRootConfigClasses() when extending AbstractAnnotationConfigDispatcherServletInitializer

你。 提交于 2019-12-17 17:20:21
问题 What is the difference between getServletConfigClasses() vs getRootConfigClasses() when extending AbstractAnnotationConfigDispatcherServletInitializer . I've been reading a lot sources since this morning but I haven't get any clear understanding on the differences yet : Please have look at these two configurations : 1). public class SpringMvcInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { @Override protected Class<?>[] getRootConfigClasses() { return new Class[] {

Spring @ComponentScan doesn't work on @Repository

放肆的年华 提交于 2019-12-14 03:26:10
问题 I have a repository in different package than the configuration class , so I annotated it as the following with @Repostiory: package test; @Repository public interface UserTest extends JpaRepository<User, Long> { } I have done the component scan on it and it didn't work : package com.app; @SpringBootApplication @ComponentScan({"test","com.app"}) public class Application extends SpringBootServletInitializer { } Exception : No qualifying bean of type 'test.UserTest' available: expected at least

How to avoid to configure an external library by another library using Spring Boot

落花浮王杯 提交于 2019-12-11 12:58:39
问题 Let’s assume I have two Spring boot projects. The first project is just a supporting library providing various functionalities. The second is the “main” project (primary library) which uses the supporting project (jar). The supporting library has some services which should be autowired by the primary project. How can I configure the supporting library so that the primary library does not have to do any configurations for the supporting library. In essence I am talking about component scan.

How to get list of Interfaces from @ComponentScan packages

删除回忆录丶 提交于 2019-12-09 05:54:43
问题 I would like to implement something similar to Spring Data. Developer can define some interfaces, add a custom annotation to the interfaces to mark them, (my code will create Proxy instances for the interfaces) and use them by @Autowire to necessary services. During spring initializing I need to get list of all the interfaces (properly annotated)< create dynamic Proxy for the interfaces and inject them where they are necessary. Proxy creation, created beans injecting is fine. Now the problem:

How to config @ComponentScan dynamic?

青春壹個敷衍的年華 提交于 2019-12-08 03:30:53
问题 @ComponentScan( //CS1 basePackages = {"com.package.A", "com.package.B"}, excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = {com.Package.A.SomeClass.class }) ) @ComponentScan( //CS2 basePackages = { "com.package.A"} ) @EnableAutoConfiguration @SpringBootApplication public class Application { public static void main(String[] args) throws Exception { ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args); } } Above is my