13

I'm running a war file on a tomcat webserver environment.

I have an annotation based config for @Beans, and a xml config for webservices:

@Configuration
//@ComponentScan(basePackageClasses = ...)
public class AppConfig {
    //beans @Bean
}

applicationContext.xml:

<beans>
    <context:component-scan base-package="..."/>
    <jaxws:endpoint ... />
</bean>

Problem: I would like to define @ComponentScan by annotation only to have typesafety. But if I do so, the scanning is not performed. In contrast, when I use <context:component-scan.. everything works fine.

Is Spring component scanning within a webserver tied to configuration with xml for the package scanning?

membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • http://stackoverflow.com/questions/24130166/componentscan-basepackageclasses-vs-componentscan-basepackages-to-register-a-sin – Stefan Jul 22 '14 at 09:52

1 Answers1

26

Go through http://docs.spring.io/spring-javaconfig/docs/1.0.0.M4/reference/html/ch06s02.html Something Like.

    @Configuration
    @ComponentScan("com.company") // search the com.company package for @Component classes
    @ImportXml("classpath:com/company/data-access-config.xml")        
    public class Config {
    }
Swaraj
  • 589
  • 4
  • 15