component-scan

How to config @ComponentScan dynamic?

允我心安 提交于 2019-12-06 13:13:11
@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 SpringBootApplication 's main class. As you can see,I have to use Annnotation ,not xml . There are two @ComponentScan

How to get list of Interfaces from @ComponentScan packages

人走茶凉 提交于 2019-12-03 07:20:41
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 find the list of all the interfaces? They could be placed in any package (or even in a separate

Adding configuration class to SpringBootTest breaks component scan

余生颓废 提交于 2019-12-02 13:38:13
问题 I am trying to disable real Mongo connection and replace it with Fongo mock in tests. Here is my test class: @SpringBootTest @RunWith(SpringRunner.class) public class ControllerTest { @Autowired private WebApplicationContext wac; @Autowired private ObjectMapper objectMapper; @MockBean private MyService service; private MockMvc mockMvc; @Before public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); } @Test public void performTest() throws Exception { ...

Error Injecting FeignClient from another Project

空扰寡人 提交于 2019-11-29 02:04:30
问题 I am having trouble auto wiring a feign client from another project. It appears that the implementation of the feign client is not being generated and injected. This is the error I am getting. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'passportRestController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.wstrater.service.contacts.client

getServletConfigClasses() vs getRootConfigClasses() when extending AbstractAnnotationConfigDispatcherServletInitializer

…衆ロ難τιáo~ 提交于 2019-11-28 15:04:23
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[] { ConServlet.class }; } @Override protected Class<?>[] getServletConfigClasses() { return null; } .... ...

Using @ComponentScan or <context:component-scan /> with only one class

谁说胖子不能爱 提交于 2019-11-28 09:39:15
I'm maintaining a project with two set of main packages, the project is using Spring and Spring MVC, one of these packages contains several controllers and is scanned using XML configuration ( <context:component-scan /> ). The problem is that there is a single class in the other package (not scanned), and I need this class to be scanned, but only this class and nothing else in the package. I can't change its package now since it would be too risky now. So is there a way to do this using annotations or XML ? Simply add is as a bean to your context e.g. <bean class="my.package.MyClass" /> What

SpringBootApplication exclude when ComponentScanning other @SpringBootApplications

旧时模样 提交于 2019-11-28 01:31:17
问题 I'm having some difficulty preventing Spring Boot from auto configuring some classes (in this example: SolrAutoConfiguration). To illustrate I've setup a much reduced example: https://github.com/timtebeek/componentscan-exclusions In reality there's some 20+ internal @SpringBootApplication projects, each with their own dependencies coming together. (Not ideal / not my idea, but hard to move away from now.) The problem arises because multiple subprojects are using Solr 5.2.1, but Spring Boot is

Using @ComponentScan or <context:component-scan /> with only one class

一个人想着一个人 提交于 2019-11-27 03:04:32
问题 I'm maintaining a project with two set of main packages, the project is using Spring and Spring MVC, one of these packages contains several controllers and is scanned using XML configuration ( <context:component-scan /> ). The problem is that there is a single class in the other package (not scanned), and I need this class to be scanned, but only this class and nothing else in the package. I can't change its package now since it would be too risky now. So is there a way to do this using

multiple packages in context:component-scan, spring config

本小妞迷上赌 提交于 2019-11-26 19:29:03
How can I add multiple packages in spring-servlet.xml file in context:component-scan element? I have tried <context:component-scan base-package="z.y.z.service" base-package="x.y.z.controller" /> and <context:component-scan base-package="x.y.z.service, x.y.z.controller" /> and <context:component-scan base-package="x.y.z.service" /> <context:component-scan base-package="x.y.z.controller" /> but got error: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [x.y.z.dao.daoservice.LoginDAO] found for dependency: The following approach is correct: <context

multiple packages in context:component-scan, spring config

半城伤御伤魂 提交于 2019-11-26 06:57:53
问题 How can I add multiple packages in spring-servlet.xml file in context:component-scan element? I have tried <context:component-scan base-package=\"z.y.z.service\" base-package=\"x.y.z.controller\" /> and <context:component-scan base-package=\"x.y.z.service, x.y.z.controller\" /> and <context:component-scan base-package=\"x.y.z.service\" /> <context:component-scan base-package=\"x.y.z.controller\" /> but got error: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching