首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java spring bean配置错误

Java spring bean配置错误
EN

Stack Overflow用户
提问于 2011-04-28 20:54:41
回答 2查看 20.4K关注 0票数 4

在我使用GWT开发的web应用程序Hibernate ans Spring中,我在jobClass -context.xml文件中设置应用程序bean时遇到了这种情况。

我在运行时得到以下错误:

代码语言:javascript
复制
Error 500 Error creating bean with name 'schedulerFactory' defined in class path resource [application-context.xml]:
Cannot resolve reference to bean 'cronTrigger' while setting bean property 'triggers' with key [0];

nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'cronTrigger' defined in class path resource [application-context.xml]:
Cannot resolve reference to bean 'exampleJob1' while setting bean property 'jobDetail';

nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'exampleJob1' defined in class path resource [application-context.xml]:
Initialization of bean failed;

nested exception is org.springframework.beans.TypeMismatchException:
Failed to convert property value of type [fr.web.utils.ExampleJob] to required type [java.lang.Class] for property 'jobClass';

nested exception is java.lang.IllegalArgumentException:
Cannot convert value of type [fr.web.utils.ExampleJob] to required type [java.lang.Class] for property 'jobClass':
PropertyEditor [org.springframework.beans.propertyeditors.ClassEditor] returned inappropriate value

下面是我的Java类:

代码语言:javascript
复制
public class ExampleJob extends QuartzJobBean {
    private AbsenceDao absenceDao; 
    @Override
    protected void executeInternal(JobExecutionContext context)
    throws JobExecutionException {
        List untreatedDemands = new ArrayList();
        untreatedDemands = absenceDao.getDemandsAskedNotValidated();
    }
    public AbsenceDao getAbsenceDao() {
        return absenceDao;
    }
    public void setAbsenceDao(AbsenceDao absenceDao) {
        this.absenceDao = absenceDao;
    }
}

下面是我的应用程序-context.xml:

代码语言:javascript
复制
    <!-- variables d'environnement - fichier properties -->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" id="placeholderconfig">
        <property name="fileEncoding" value="UTF-8"/>
        <property name="locations">
            <list>
                <value>classpath:internal.properties</value>
            </list>
        </property>
    </bean>

    <!-- Configuration du crontrigger -->
    <bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="cronTrigger" />
            </list>
        </property>
    </bean>
    <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail">
            <ref local="exampleJob1" />
        </property>

        <property name="cronExpression">
            <util:constant static-field="fr.web.utils.APP_VAR.CRON_EXPRESSION" />
        </property>
    </bean>

    <bean id="jobClass" class="fr.web.utils.ExampleJob">
        <property name="absenceDao" ref="absenceDao"/>
    </bean>

    <bean id="exampleJob1" class="org.springframework.scheduling.quartz.JobDetailBean">
        <property name="jobClass" ref="jobClass" />
        <property name="jobDataAsMap">
            <map>
                <entry key="timeout" value="5" />
            </map>
        </property>
    </bean>

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

    <!-- Bean containing all the properties of the application -->
    <bean class="fr.web.utils.ApplicationProperties" id="applicationProperties" lazy-init="true" scope="singleton">
        <constructor-arg index="0" value="classpath:internal.properties"/>
    </bean>

    <!-- Bean DAO -->
    <bean abstract="true" id="abstractDao">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    <bean class="fr.web.dao.AbsenceDao" id="absenceDao" parent="abstractDao"/>

    </bean>
</beans>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-04-28 21:03:55

属性jobClass需要class,而您已经给出了bean的reference,因此请更改

代码语言:javascript
复制
<bean id="exampleJob1" class="org.springframework.scheduling.quartz.JobDetailBean">
    <property name="jobClass" ref="jobClass" />
    <property name="jobDataAsMap">
        <map>
            <entry key="timeout" value="5" />
        </map>
    </property>
</bean>

to (备注:下面的value属性)

代码语言:javascript
复制
<bean id="exampleJob1" class="org.springframework.scheduling.quartz.JobDetailBean">
    <property name="jobClass" value="fr.acensi.web.utils.ExampleJob" />
    <property name="jobDataAsMap">
        <map>
            <entry key="timeout" value="5" />
        </map>
    </property>
</bean>
票数 2
EN

Stack Overflow用户

发布于 2012-09-03 22:16:28

这里有另一个选项,你可能认为更整洁或不整洁,我喜欢它,因为它保持了上下文的清晰度。

代码语言:javascript
复制
<bean id="exampleJob1" class="org.springframework.scheduling.quartz.JobDetailBean">
  <property name="jobClass">
    <bean factory-bean="jobClass" factory-method="getClass" />
  </property>
</bean>

正如Jigar Joshi所描述的那样,问题的解决方案略有不同。它允许您将bean jobClass实例化与JobDetailbean的构建分离开来。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5818922

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档