jeudi 12 mars 2015

Is Spring Profile application context specific?

I've created a web project with parent child application context configured. The root application context configured with infrastructure beans(Datasource, Transaction, ORM, Cache, security), and web application context configured with view resolvers, and all of this beans are group under relative profiles as follows:



<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>
xml,
cache,JDK,Ehcache,Redis,Memcache,xmemcached-Client,Composite,
db,C3P0,
orm,Hibernate,Hibernate4,
transaction
</param-value>
</context-param>

<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:servlet/rest-servlet.xml</param-value>
</init-param>
<init-param>
<param-name>spring.profiles.active</param-name>
<param-value>xml,combined</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>


when i try to lanch this project, i got this error :



org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheTestController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.test.springbasic.service.impl.ContactService org.test.springbasic.controller.CacheTestController.contactService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.test.springbasic.service.impl.ContactService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}


I wanna know dose spring profile application context specific (my controllers under child context, and my services under root context and autowired to controllers), the ContactService is annotated with @Profile({ "Hibernate" }), why I can't get the bean, It is there, I've acitive the "Hibernate" profile under spring.profiles.default context-param!


Aucun commentaire:

Enregistrer un commentaire