No bean named '##' is defined serverless framework Spring

69 views Asked by At

I have this problem, I'm working with Spring, Hibernate, JPA and serverless framework. When I invoke the class form the console I got this error "

"errorMessage": "No bean named 'wizardDao' is defined",
    "errorType": "org.springframework.beans.factory.NoSuchBeanDefinitionException",
    "stackTrace": [
        "org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:694)",
        "org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1168)",
        "org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:281)",
        "org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)",
        "org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956)",
        "com.serverless.dao.Handler.handleRequest(Handler.java:30)",
        "com.serverless.dao.Handler.handleRequest(Handler.java:17)"

but if I prove the class in Eclipse with I main class there's not problema. I don't know what is going wrong this is my applicationContext

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd 
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd 
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd 
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">

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

    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="Things-serverless" />
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

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

    <task:scheduler id="taskScheduler" />
    <task:executor id="taskExecutor" pool-size="1" />
    <task:annotation-driven executor="taskExecutor"
        scheduler="taskScheduler" />
    <!-- <bean id="serviceBean" class="com.serverless.test" /> -->

</beans>

this is my dao class

@Component
public class WizardDao extends ForwardedMessageDao {
    private static final long serialVersionUID = 5302145657830590489L;

    /**
     * Get all wizards from data base.
     * 
     * @param
     * @return List of wizards
     */
    @SuppressWarnings("unchecked")
    public List<Wizard> getAllWizards() {
        Query query = getEmf().createQuery("FROM Wizard");
        System.out.println("aqui ");
        return (List<Wizard>) query.getResultList();
}
}

and this is my handdler class

@Service
@Transactional
public class Handler implements RequestHandler<Map<String, Object>, ApiGatewayResponse> {

    private static final Logger LOG = Logger.getLogger(Handler.class);

    @Autowired
    private WizardDao wizardDao;

    @Override
    public ApiGatewayResponse handleRequest(Map<String, Object> input, Context context) {
        BasicConfigurator.configure();
        Map<String, Wizard> response = new HashMap<>();
        Response responseBody = new Response("start", response);
        try {
            wizardDao = Application.getBean(WizardDao.class);
            List<Wizard> listWizard = wizardDao.getAllWizards();
            for (Wizard wizard : listWizard) {
                response.put("" + wizard.getIdWizard(), wizard);
            }
            responseBody.setInput(response);
        } catch (Exception e) {
            responseBody.setMessage("Fail: " + e.getMessage());
        }
        LOG.info("received: " + input);
        return ApiGatewayResponse.builder().setStatusCode(200).setObjectBody(responseBody)
                .setHeaders(Collections.singletonMap("fur", "this sheep")).build();
    }
}

and this is my entityManager Class

public class EntityManagerDao implements Serializable {
    private static final long serialVersionUID = -6969245506190987187L;

    @PersistenceContext(unitName = "Things-serverless")
    private EntityManager em;

    /**
     * @return the em
     */
    public EntityManager getEmf() {
        return em;
    }

}
0

There are 0 answers