0

I google for the whole but could not figure out whats wrong in my code, and why its not autowiring.

****EMPLOYEE CONTROLLER****

import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.rectrix.eob.master.BankMaster;
import com.rectrix.eob.service.BankMasterService;
import com.rectrix.eob.service.impl.BankMasterServiceImpl;

@Controller
@RequestMapping(value="/")
@Scope(value="request")
public class EmployeeController  {

    @Autowired
    BankMasterService bankMasterService;


    @Autowired
    BankMaster bankMaster;



    public EmployeeController() {
        super();
        // TODO Auto-generated constructor stub
    }
    static Logger log = Logger.getLogger(EmployeeController.class.getName());

    @RequestMapping(value="*")
    public @ResponseBody String bankData(HttpServletRequest request, HttpServletResponse response){
    BankMaster bankMaster = new BankMaster();
    bankMaster.setName("kotak");
        bankMasterService.saveBankName(bankMaster);
        return "i am in bank";
    }

}

BANK MASTER MODEL

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;    
import javax.persistence.Table;

@Entity
@Table(name="TB_BANK_MASTER")
public class BankMaster implements Serializable {

    @Id
    @GeneratedValue
    @Column(name="BANK_ID")
    private Long bankId;

    @Column(name="BANK_NAME")
    private String name;

public BankMaster() {
    // TODO Auto-generated constructor stub
}

    public Long getBankId() {
        return bankId;
    }

    public void setBankId(Long bankId) {
        this.bankId = bankId;
    }

    /**
     * get the bank name
     * @return String
     */
    public String getName() {
        return name;
    }

    /**
     * set the bank name    
     * @param bankName
     */
    public void setName(String name) {
        this.name = name;
    }
}

Application context

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.1.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">

    <context:annotation-config />
    <context:component-scan base-package="com.rectrix.eob"></context:component-scan>

    <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations" value="classpath:system.properties" />
    </bean>
    <bean
        class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
    <bean
        class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />

    <!-- MYSQL HIBERNATE CONFIGURATION  -->

    <jee:jndi-lookup jndi-name="${jndi.datasource}" id="dataSource"
        expected-type="javax.sql.DataSource"></jee:jndi-lookup>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com.rectrix.eob" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
            </props>
        </property>
    </bean>

    <bean class="org.springframework.orm.hibernate4.HibernateTransactionManager"
        id="transactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
        <property name="dataSource" ref="dataSource" />
    </bean>


    <bean id="persistenceExceptionTranslationPostProcessor"
        class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"></bean>

    <tx:annotation-driven transaction-manager="transactionManager" />

    <task:annotation-driven />

</beans>

****Error what I got is ****

11:05:32,579 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/eob-web].[spring-mvc]] (http-localhost/127.0.0.1:8080-1) JBWEB000236: Servlet.service() for servlet spring-mvc threw exception: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.rectrix.eob.master.BankMaster] 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)}

Please help me find the solution for my issue that i am face. Thanks in advance

Nitesh kumar
  • 348
  • 2
  • 8
  • 25
  • 1
    `BankMaster` is an entity you cannot `Autowire` it directly. Actually why do you want to `Autowire` an entity? If you explain your needs instead of your error may be I can help. – bhdrkn Oct 20 '15 at 05:51
  • there is a need of taking a data from the front end and want to store it in the data base in those respective entities. Right now i need to check flow of data from the controller to service layer and to dao and database, before my team starts any further coding – Nitesh kumar Oct 20 '15 at 05:58
  • Your bankData method already saves a BankMaster to database so why do you try to inject BankMaster entity? I think no need for that. Just remove it and you ready to go. If you want to just track your data you may just log them in the methods. – bhdrkn Oct 20 '15 at 06:08
  • For that you don't need an auto wired entity. Use it as a model object instead. Remove the request scope, remove the auto wired variable and just add it as a method argument. – M. Deinum Oct 20 '15 at 06:08

0 Answers0