Могу ли я использовать $ {‹exp_string›} вместо # {‹exp_string›} в SpEL в Spring 3.0.x?

Я использую SpEL в своем файле конфигурации xml. По ошибке я использовал $ {} вместо # {}, но он работает. могу я заменить # на $? Вот мой код

config-servlet.xml

<?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:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee"
    xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
    <context:component-scan base-package="com.balancesheetreconcile" />
    <context:property-placeholder
        location="classpath:database.properties classpath:mail-configuration.properties" />
    <mvc:resources location="/resources/" mapping="/resources/**" />
    <mvc:annotation-driven />
    <tx:annotation-driven proxy-target-class="true" />
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"
        p:prefix="/WEB-INF/views/" p:suffix=".jsp">
    </bean>
    <bean id="dateEditor"
        class="org.springframework.beans.propertyeditors.CustomDateEditor">

        <constructor-arg>
            <bean class="java.text.SimpleDateFormat">
                <constructor-arg value="dd-MM-yyyy" />
            </bean>
        </constructor-arg>
        <constructor-arg value="false" />
    </bean>
    <bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
        <property name="customEditors">
            <map>
                <entry key="java.util.Date">
                    <ref bean="dateEditor" />
                </entry>
            </map>
        </property>
    </bean>

    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource"
        p:driverClassName="${jdbc.driverClassName}" p:username="${jdbc.username}"
        p:password="${jdbc.password}" p:url="${jdbc.url}" />

    <bean id="dataSourceSessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
            </props>
        </property>
        <property name="packagesToScan">
            <list>
                <value>com.balancesheetreconcile.entities</value>
            </list>
        </property>
    </bean>
    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />

    <bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager"
        p:sessionFactory-ref="dataSourceSessionFactory" />

    <bean id="taskScheduler" class="com.balancesheetreconcile.utilities.TaskScheduler"
        init-method="scheduleTask" />

    <!-- Mail Sender bean -->

    <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="host" value="${host}" />
        <property name="port" value="${port}" />
        <property name="username" value="${sender_username}" />
        <property name="password" value="${sender_password}" />
        <property name="javaMailProperties">
        <props>
                <prop key="${smtp_auth}">true</prop>
                <prop key="${enable_ssl_tls}">true</prop>
                <prop key="${mailing_protocol}">smtp</prop>
                <prop key="${debug}">true</prop>
            </props>
        </property>
        </bean>
</beans>

Я все еще не уверен в этом. пожалуйста, помогите. заранее спасибо


person Mukesh Kumar Saini    schedule 20.05.2014    source источник
comment
возможный дубликат Как язык выражений Spring 3 взаимодействует со свойством заполнители?   -  person Luca Basso Ricci    schedule 20.05.2014


Ответы (1)


${...} разрешаются заполнителем свойств из mail-configuration.properties.

Это полностью отличается от SpEL, который оценивает выражения (обычно не только простые свойства) во время инициализации контекста.

Например, #{someBean.foo} получит значение, вызвав getFoo() на someBean, и

#{SystemProperties['bar']} будет использовать значение из свойства системы бара

(java ... -Dbar=baz).

person Gary Russell    schedule 20.05.2014