I'm getting this error when I try to autowire interface that extends CrudRepository. I have two hibernate xml configs for 2 databases. The full stack is
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'helloController': Unsatisfied dependency expressed through field 'stockService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.publishing.test.stock.services.StockService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url"></property>
<property name="connection.username"></property>
<property name="connection.password"></property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">100</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.PostgreSQL95Dialect</property>
<!-- Disable the second-level cache -->
<!--<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>-->
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop the existing table and create new one -->
<property name="hbm2ddl.auto">update</property>
<property name="packagesToScan">com.publishing</property>
<!-- Mention here all the model classes -->
<mapping class="com.publishing.models.Stock"/>
</session-factory>
@Controller
public class HelloController {
@Autowired
private StockService stockService;
I have 3 lines also in Spring Config
<context:component-scan base-package="com.publishing" />
<context:annotation-config />
<jpa:repositories base-package="com.publishing" />
Service is
@Service("StockService")
public interface StockService extends CrudRepository<Stock, Long> {
Edit:
Ok, now we have edited hibernate.cfg.xml
<!-- Drop the existing table and create new one -->
<property name="hbm2ddl.auto">update</property>
<!--<property name="packagesToScan">com.publishing</property>-->
<!-- Mention here all the model classes -->
<mapping class="com.publishing.models.Stock"/>
And service
@Service("stockService")
public interface StockService extends CrudRepository<Stock, Long> {