简体   繁体   English

使用XML通过字符串以外的属性来配置Spring Bean(使用属性文件)

[英]Configure Spring Bean using XML through Property other than String (using Properties File)

I have a Spring Bean defined as: 我有一个定义为:

<bean id="loyaltyPointsExpiringJobTrigger"  class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="name" value="Loyalty Points Expiring Job Trigger" />
        <property name="jobDetail" ref="loyaltyPointsExpiringJobDetail" />
        <property name="cronExpression" value="${prop.loyalty.expiring.points.job.cron}"/>
        <property name="timeZone" value="${prop.loyalty.expiring.points.timezone}"/>
    </bean>

However, the property prop.loyalty.expiring.points.timezone is causing TypeMismatchException with the message: 但是,属性prop.loyalty.expiring.points.timezone导致TypeMismatchException与以下消息:

org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'java.util.TimeZone' for property 'timeZone'; org.springframework.beans.TypeMismatchException:无法将类型“ java.lang.String”的属性值转换为属性“ timeZone”的必需类型“ java.util.TimeZone”; nested exception is java.lang.IllegalArgumentException: Invalid time zone specification '${prop.loyalty.expiring.points.timezone}' 嵌套异常为java.lang.IllegalArgumentException:无效的时区规范'$ {prop.loyalty.expiring.points.timezone}'

Please guide. 请指导。

这很简单,您可能需要为timeZone对象定义一个bean,并找出使用字符串的构造函数,并传递所需的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用来自其他bean属性的xml配置设置Spring bean属性 - Spring bean property set using xml configuration from other bean property 在 Spring XML 配置文件中使用属性字符串 - Using Properties String in Spring XML configuration file 使用/转换XML文件到Spring bean定义 - Using/converting an XML file to a Spring bean definition Spring Boot:使用 Java Bean 类从 application.properties 文件中读取 spring.jms.jndi-name 属性 - Spring Boot: Reading spring.jms.jndi-name property from application.properties file using a Java Bean class 如何使用.properties文件中的值初始化spring bean中的集合 - How to initialize a set in a spring bean using value from .properties file 通过propeties在xml配置中将spring bean配置为抽象或不抽象 - Configure spring bean to be abstract or not in xml configuration through propeties 列表中的春豆 <String> 在属性文件中 - spring bean from list<String> in a properties file 使用Spring配置应用程序属性 - Using spring to configure application properties 如何在Spring中定义String数组的bean(使用XML配置) - How to define a bean of String array in Spring (using XML configuration) 除了log4j xml、properties文件、源代码(主要是java)之外的其他日志的配置方式? - Ways to configure logs other than log4j xml, properties file, and source code (mainly java)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM