0
votes

Here is the error...

Deployment Error for module: EBlood: Error occurred during deployment: 
Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'categoryService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: 
Could not autowire field: public com.iu.eblood.daoImp.CategoryDaoImp com.iu.eblood.serviceImp.CategoryService.categoryDaoImp; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No matching bean of type [com.iu.eblood.daoImp.CategoryDaoImp] 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), @org.springframework.beans.factory.annotation.Qualifier(value=categorydaoimp)}. 
Please see server.log for more details.
3

3 Answers

3
votes

The key is this :

No matching bean of type [com.iu.eblood.daoImp.CategoryDaoImp] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency

which means you need to have at least on of that bean defined either in the XML or with @Component

0
votes
package com.iu.eblood.dao;

import java.io.Serializable;
import java.util.Collection;

 public interface GenericDaoInterface<T,PK extends Serializable> {

/** Persist the newInstance object into database */
PK create(T newInstance);

/** Retrieve an object that was previously persisted to the database using
 *   the indicated id as primary key
 */
T read(PK id);

/** Save changes made to a persistent object.  */
void update(T transientObject);

/** Remove an object from persistent storage in the database */
void delete(T persistentObject);


/*Get all Data giving specific**/
Collection<T> loadAll();

}


package com.iu.eblood.dao;

 import java.io.Serializable;

 import java.util.Collection;


  import org.hibernate.criterion.Restrictions;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.orm.hibernate3.HibernateTemplate;




  public abstract class GenericDao<T,PK extends Serializable> 
  implements GenericDaoInterface<T, Serializable>   
  {
@Autowired
protected HibernateTemplate hibernateTemplate;


public GenericDao(Class<T> persistentClass)
{
    setPersistentClass(persistentClass);    
}

private Class<T> persistentClass;

public Class<T> getPersistentClass() {
    return persistentClass;
}

protected void setPersistentClass(Class<T> persistentClass) {
    this.persistentClass = persistentClass;
}

public Serializable create(T newInstance) {
    return hibernateTemplate.save(newInstance);

}

public T read(Serializable id) {
    return (T) hibernateTemplate.get(persistentClass,id);
}

public void update(T transientObject) {

    hibernateTemplate.update(transientObject);

}

public void delete(T persistentObject) {

    /*
     * Update DeletedDate for Entity*/
    update(persistentObject);

}

public Collection<T> loadAll() {
  return hibernateTemplate.loadAll(persistentClass);

}

@SuppressWarnings("unchecked")
public T loadByField(String fieldName, Object fieldValue) {

    return (T) hibernateTemplate.getSessionFactory().getCurrentSession().createCriteria(persistentClass).
            add(Restrictions.eq(fieldName, fieldValue)).uniqueResult();
}

@SuppressWarnings("unchecked")
public Collection<T> loadAllByField(String fieldName, Object fieldValue) {

    return        hibernateTemplate.getSessionFactory().getCurrentSession().createCriteria(persistentClass).
            add(Restrictions.eq(fieldName, fieldValue)).list();
}

 }


package com.iu.eblood.daoImp;


 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.orm.hibernate3.HibernateTemplate;
 import org.springframework.stereotype.Repository;

  import com.iu.eblood.dao.GenericDao;
   import com.iu.eblood.model.Category;

  @Repository("categorydaoimp")
  public class CategoryDaoImp extends GenericDao<Category, Long> {


public CategoryDaoImp() {

    super(Category.class);
}


 }

Appcontext content

  <bean id="sessionFactory"
       class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="DB2DataSource" />
    <property name="packagesToScan" value="com.iu.eblood.model" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.format_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
        </props>
    </property>
</bean>

<bean id="hibernateTemplate"       class="org.springframework.orm.hibernate3.HibernateTemplate">
    <constructor-arg>
        <ref bean="sessionFactory" />
    </constructor-arg>
</bean>
0
votes

Do you have this line in your spring XMLs ?

<context:component-scan base-package="com.iu.eblood"/>

if so have you tried annotating your Dao with

@Repository

instead of

@Repository("categorydaoimp")