简体   繁体   中英

BeansException occured :Cannot find class for bean with name 'conslEngineDAO'

THIS IS NOT FULL CODE AS I'M NOT THE ONE WHO WROTE IT, I'M JUST DEBUGGING IT.PLEASE LET ME KNOW IF I NEED TO ADD ANYTHING I'm trying to debug a standalone class called DroppedToCheckReportProcess.java for some other error, but now I'm getting this error and I can seem to figure out what is the issue. Any help would be appreciated. Am I missing something in Application-context or spring-bean file. Stacktrace at the end.


DroppedToCheckReportProcess.java

getBean() throws the error NoSuchBeanFound I've check other queries similar to this, but all says @Autowire is required, but it doesn't seem to work for me. This is a legacy code which is why it is not quite possible to have wrong code as I have fetched from latest git branch. It does not have a resource folder as well all the config files are in config folder.

public class DroppedToCheckReportProcess {
    public static void main(String[] args) {
    dtcRptProc.getBean();
    PayerTO payerTO = null;
    List reorigCheckPaymentList = new ArrayList();
    List dtpcRptRecList = new ArrayList();
    ArrayList fetchPayerList = (ArrayList) enrollDAO.fetchPayers();
    List uhcPayerList =  new ArrayList(enrollDAO.getPayerList());
    protected void getBean() {
        String strContext = "getBean()";
        logger.debug(strContext, "Start");
        try {
            String aContxt = BatchProperties.getInstance().getProperty("APPLICATION_CONTEXT");
            aContxt = aContxt + "_" + System.getProperty("eps.env") + ".xml";
            String sBeanCtx = BatchProperties.getInstance().getProperty("SPRING_BEANS");
            String[] configFiles = new String[] { aContxt, sBeanCtx };
            appContext = new ClassPathXmlApplicationContext(configFiles);
            enrollDAO = (EnrollmentDAO) appContext.getBean("enrollmentDAO");
            mPaymentDAO = (PaymentDAO) appContext.getBean("paymentDAO");
            mPayorDAO = (PayorDAO) appContext.getBean("payorDAO");
            logger.debug(strContext, "End");
        } catch (BeansException e) {
            logger.error(strContext, "BeansException occured :" + e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(strContext, "Exception occured :" + e.getMessage());
            System.exit(2);
        }
    }

APPLICATION_CONTEXT

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <!-- DATA SOURCE CONFIG -->
    <bean name="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
         <property name="driverClassName">
              <value>org.postgresql.Driver</value>
         </property>
         <property name="url">
             <value>jdbc:postgresql://test</value>
        </property>
        <property name="username">
             <value>test</value>
        </property>
        <property name="password">
<value>test</value>
        </property>
    </bean>
    <!-- COMMON SESSION FACTORY CONFIG -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource">
               <ref bean="dataSource"/>
        </property>
        <property name="hibernateProperties">
                <props>
                      <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                      <prop key="hibernate.show_sql">false</prop>
                      <prop key="hibernate.default_schema">ole</prop>
                      <prop key="hibernate.dbcp.initialSize">1</prop>
                      <prop key="hibernate.dbcp.maxTotal">100</prop>
                      <prop key="hibernate.dbcp.maxActive">100</prop>
                      <prop key="hibernate.dbcp.maxIdle">50</prop>
                      <prop key="hibernate.dbcp.minIdle">0</prop>
                      <prop key="hibernate.dbcp.maxConnLifetimeMillis">-1</prop>
                      <prop key="hibernate.dbcp.minEvictableIdleTimeMillis">1000 * 60 * 30</prop>
                      <prop key="hibernate.dbcp.validationQueryTimeout">300</prop>
                      <prop key="hibernate.dbcp.maxWait">-1</prop>
                      <prop key="hibernate.dbcp.testOnBorrow">true</prop>
                      <prop key="hibernate.dbcp.validationQuery">select ctl_grp_id from ole.ctl_grp fetch first 1 row only with ur;</prop>
                </props>
        </property>
    </bean>
<!-- HIBERNATE TEMPLATE CONFIG -->
<!--  Common Template Configuration Starts -->
    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
        <property name="sessionFactory">
             <ref bean="sessionFactory"/>
        </property>
    </bean>
</beans>

SPRING_BEAN

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

    <!-- DAO OBJECTS DEFINED -->
    <bean id="conslEngineDAO" class="com.batch.dao.impl.ConslEngineDAOImpl">
        <property name="hibernateTemplate">
            <ref bean="hibernateTemplate"/>
        </property>
    </bean>

    <bean id="conslEngineService" class="com.batch.services.impl.ConslEngineServiceImpl">
        <property name="conslEngineDAO">
            <ref bean="conslEngineDAO"/>
        </property>
    </bean>
    <bean id="procCtlDAO" class="com.batch.dao.impl.ProcCtlDAOImpl">
        <property name="hibernateTemplate">
            <ref bean="hibernateTemplate"/>
        </property>
    </bean>

    <bean id="procCtlService" class="com.batch.services.impl.ProcCtlServiceImpl">
        <property name="procCtlDAO">
            <ref bean="procCtlDAO"/>
        </property>
    </bean>
    </beans>

STACK TRACE

Aug 28, 2022 3:34:09 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@fba92d3: defining beans [dataSource,sessionFactory,hibernateTemplate,conslEngineDAO,conslEngineService,procCtlDAO,procCtlService]; root of factory hierarchy
15:34:09.041 [main] INFO  o.hibernate.impl.SessionFactoryImpl - closing
Aug 28, 2022 3:34:09 PM org.springframework.orm.hibernate3.AbstractSessionFactoryBean destroy
INFO: Closing Hibernate SessionFactory
15:34:09.075 [main] ERROR com.uhg.exante.dbp.batch.processor.DroppedToCheckReportProcess - getBean() :: BeansException occured :Cannot find class [com.uhg.optumHealth.batch.dao.impl.ConslEngineDAOImpl] for bean with name 'conslEngineDAO' defined in class path resource [config/spring-beans.xml]; nested exception is java.lang.ClassNotFoundException: com.uhg.optumHealth.batch.dao.impl.ConslEngineDAOImpl
java.lang.NullPointerException
    at com.uhg.exante.dbp.batch.processor.DroppedToCheckReportProcess.main(DroppedToCheckReportProcess.java:96)

Looks like you import the wrong class. The error message mentions:

com.uhg.optumHealth.batch.dao.impl.ConslEngineDAOImpl

the XML file:

com.batch.dao.impl.ConslEngineDAOImpl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM