简体   繁体   English

如何将属性值注入使用注释配置的 Spring Bean?

[英]How can I inject a property value into a Spring Bean which was configured using annotations?

I have a bunch of Spring beans which are picked up from the classpath via annotations, eg我有一堆 Spring bean,它们是通过注释从类路径中提取的,例如

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
    // Implementation omitted
}

In the Spring XML file, there's a PropertyPlaceholderConfigurer defined:在 Spring XML 文件中,定义了一个PropertyPlaceholderConfigurer

<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/app.properties" />
</bean> 

I want to inject one of the properties from app.properites into the bean shown above.我想将 app.properites 中的一个属性注入到上面显示的 bean 中。 I can't simply do something like我不能简单地做类似的事情

<bean class="com.example.PersonDaoImpl">
    <property name="maxResults" value="${results.max}"/>
</bean>

Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations).因为 PersonDaoImpl 在 Spring XML 文件中没有特征(它是通过注释从类路径中提取的)。 I've got as far as the following:我有以下几点:

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {

    @Resource(name = "propertyConfigurer")
    protected void setProperties(PropertyPlaceholderConfigurer ppc) {
    // Now how do I access results.max? 
    }
}

But it's not clear to me how I access the property I'm interested in from ppc ?但我不清楚如何从ppc访问我感兴趣的财产?

I have a bunch of Spring beans which are picked up from the classpath via annotations, eg我有一堆 Spring bean,它们是通过注释从类路径中提取的,例如

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
    // Implementation omitted
}

In the Spring XML file, there's a PropertyPlaceholderConfigurer defined:在 Spring XML 文件中,定义了一个PropertyPlaceholderConfigurer

<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/app.properties" />
</bean> 

I want to inject one of the properties from app.properites into the bean shown above.我想将 app.properites 中的一个属性注入到上面显示的 bean 中。 I can't simply do something like我不能简单地做类似的事情

<bean class="com.example.PersonDaoImpl">
    <property name="maxResults" value="${results.max}"/>
</bean>

Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations).因为 PersonDaoImpl 在 Spring XML 文件中没有特征(它是通过注释从类路径中提取的)。 I've got as far as the following:我有以下几点:

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {

    @Resource(name = "propertyConfigurer")
    protected void setProperties(PropertyPlaceholderConfigurer ppc) {
    // Now how do I access results.max? 
    }
}

But it's not clear to me how I access the property I'm interested in from ppc ?但我不清楚如何从ppc访问我感兴趣的财产?

I have a bunch of Spring beans which are picked up from the classpath via annotations, eg我有一堆 Spring bean,它们是通过注释从类路径中提取的,例如

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
    // Implementation omitted
}

In the Spring XML file, there's a PropertyPlaceholderConfigurer defined:在 Spring XML 文件中,定义了一个PropertyPlaceholderConfigurer

<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/app.properties" />
</bean> 

I want to inject one of the properties from app.properites into the bean shown above.我想将 app.properites 中的一个属性注入到上面显示的 bean 中。 I can't simply do something like我不能简单地做类似的事情

<bean class="com.example.PersonDaoImpl">
    <property name="maxResults" value="${results.max}"/>
</bean>

Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations).因为 PersonDaoImpl 在 Spring XML 文件中没有特征(它是通过注释从类路径中提取的)。 I've got as far as the following:我有以下几点:

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {

    @Resource(name = "propertyConfigurer")
    protected void setProperties(PropertyPlaceholderConfigurer ppc) {
    // Now how do I access results.max? 
    }
}

But it's not clear to me how I access the property I'm interested in from ppc ?但我不清楚如何从ppc访问我感兴趣的财产?

I have a bunch of Spring beans which are picked up from the classpath via annotations, eg我有一堆 Spring bean,它们是通过注释从类路径中提取的,例如

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
    // Implementation omitted
}

In the Spring XML file, there's a PropertyPlaceholderConfigurer defined:在 Spring XML 文件中,定义了一个PropertyPlaceholderConfigurer

<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/app.properties" />
</bean> 

I want to inject one of the properties from app.properites into the bean shown above.我想将 app.properites 中的一个属性注入到上面显示的 bean 中。 I can't simply do something like我不能简单地做类似的事情

<bean class="com.example.PersonDaoImpl">
    <property name="maxResults" value="${results.max}"/>
</bean>

Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations).因为 PersonDaoImpl 在 Spring XML 文件中没有特征(它是通过注释从类路径中提取的)。 I've got as far as the following:我有以下几点:

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {

    @Resource(name = "propertyConfigurer")
    protected void setProperties(PropertyPlaceholderConfigurer ppc) {
    // Now how do I access results.max? 
    }
}

But it's not clear to me how I access the property I'm interested in from ppc ?但我不清楚如何从ppc访问我感兴趣的财产?

I have a bunch of Spring beans which are picked up from the classpath via annotations, eg我有一堆 Spring bean,它们是通过注释从类路径中提取的,例如

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
    // Implementation omitted
}

In the Spring XML file, there's a PropertyPlaceholderConfigurer defined:在 Spring XML 文件中,定义了一个PropertyPlaceholderConfigurer

<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/app.properties" />
</bean> 

I want to inject one of the properties from app.properites into the bean shown above.我想将 app.properites 中的一个属性注入到上面显示的 bean 中。 I can't simply do something like我不能简单地做类似的事情

<bean class="com.example.PersonDaoImpl">
    <property name="maxResults" value="${results.max}"/>
</bean>

Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations).因为 PersonDaoImpl 在 Spring XML 文件中没有特征(它是通过注释从类路径中提取的)。 I've got as far as the following:我有以下几点:

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {

    @Resource(name = "propertyConfigurer")
    protected void setProperties(PropertyPlaceholderConfigurer ppc) {
    // Now how do I access results.max? 
    }
}

But it's not clear to me how I access the property I'm interested in from ppc ?但我不清楚如何从ppc访问我感兴趣的财产?

I have a bunch of Spring beans which are picked up from the classpath via annotations, eg我有一堆 Spring bean,它们是通过注释从类路径中提取的,例如

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
    // Implementation omitted
}

In the Spring XML file, there's a PropertyPlaceholderConfigurer defined:在 Spring XML 文件中,定义了一个PropertyPlaceholderConfigurer

<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/app.properties" />
</bean> 

I want to inject one of the properties from app.properites into the bean shown above.我想将 app.properites 中的一个属性注入到上面显示的 bean 中。 I can't simply do something like我不能简单地做类似的事情

<bean class="com.example.PersonDaoImpl">
    <property name="maxResults" value="${results.max}"/>
</bean>

Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations).因为 PersonDaoImpl 在 Spring XML 文件中没有特征(它是通过注释从类路径中提取的)。 I've got as far as the following:我有以下几点:

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {

    @Resource(name = "propertyConfigurer")
    protected void setProperties(PropertyPlaceholderConfigurer ppc) {
    // Now how do I access results.max? 
    }
}

But it's not clear to me how I access the property I'm interested in from ppc ?但我不清楚如何从ppc访问我感兴趣的财产?

I have a bunch of Spring beans which are picked up from the classpath via annotations, eg我有一堆 Spring bean,它们是通过注释从类路径中提取的,例如

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
    // Implementation omitted
}

In the Spring XML file, there's a PropertyPlaceholderConfigurer defined:在 Spring XML 文件中,定义了一个PropertyPlaceholderConfigurer

<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/app.properties" />
</bean> 

I want to inject one of the properties from app.properites into the bean shown above.我想将 app.properites 中的一个属性注入到上面显示的 bean 中。 I can't simply do something like我不能简单地做类似的事情

<bean class="com.example.PersonDaoImpl">
    <property name="maxResults" value="${results.max}"/>
</bean>

Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations).因为 PersonDaoImpl 在 Spring XML 文件中没有特征(它是通过注释从类路径中提取的)。 I've got as far as the following:我有以下几点:

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {

    @Resource(name = "propertyConfigurer")
    protected void setProperties(PropertyPlaceholderConfigurer ppc) {
    // Now how do I access results.max? 
    }
}

But it's not clear to me how I access the property I'm interested in from ppc ?但我不清楚如何从ppc访问我感兴趣的财产?

I have a bunch of Spring beans which are picked up from the classpath via annotations, eg我有一堆 Spring bean,它们是通过注释从类路径中提取的,例如

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
    // Implementation omitted
}

In the Spring XML file, there's a PropertyPlaceholderConfigurer defined:在 Spring XML 文件中,定义了一个PropertyPlaceholderConfigurer

<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/app.properties" />
</bean> 

I want to inject one of the properties from app.properites into the bean shown above.我想将 app.properites 中的一个属性注入到上面显示的 bean 中。 I can't simply do something like我不能简单地做类似的事情

<bean class="com.example.PersonDaoImpl">
    <property name="maxResults" value="${results.max}"/>
</bean>

Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations).因为 PersonDaoImpl 在 Spring XML 文件中没有特征(它是通过注释从类路径中提取的)。 I've got as far as the following:我有以下几点:

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {

    @Resource(name = "propertyConfigurer")
    protected void setProperties(PropertyPlaceholderConfigurer ppc) {
    // Now how do I access results.max? 
    }
}

But it's not clear to me how I access the property I'm interested in from ppc ?但我不清楚如何从ppc访问我感兴趣的财产?

I have a bunch of Spring beans which are picked up from the classpath via annotations, eg我有一堆 Spring bean,它们是通过注释从类路径中提取的,例如

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
    // Implementation omitted
}

In the Spring XML file, there's a PropertyPlaceholderConfigurer defined:在 Spring XML 文件中,定义了一个PropertyPlaceholderConfigurer

<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/app.properties" />
</bean> 

I want to inject one of the properties from app.properites into the bean shown above.我想将 app.properites 中的一个属性注入到上面显示的 bean 中。 I can't simply do something like我不能简单地做类似的事情

<bean class="com.example.PersonDaoImpl">
    <property name="maxResults" value="${results.max}"/>
</bean>

Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations).因为 PersonDaoImpl 在 Spring XML 文件中没有特征(它是通过注释从类路径中提取的)。 I've got as far as the following:我有以下几点:

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {

    @Resource(name = "propertyConfigurer")
    protected void setProperties(PropertyPlaceholderConfigurer ppc) {
    // Now how do I access results.max? 
    }
}

But it's not clear to me how I access the property I'm interested in from ppc ?但我不清楚如何从ppc访问我感兴趣的财产?

I have a bunch of Spring beans which are picked up from the classpath via annotations, eg我有一堆 Spring bean,它们是通过注释从类路径中提取的,例如

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
    // Implementation omitted
}

In the Spring XML file, there's a PropertyPlaceholderConfigurer defined:在 Spring XML 文件中,定义了一个PropertyPlaceholderConfigurer

<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/app.properties" />
</bean> 

I want to inject one of the properties from app.properites into the bean shown above.我想将 app.properites 中的一个属性注入到上面显示的 bean 中。 I can't simply do something like我不能简单地做类似的事情

<bean class="com.example.PersonDaoImpl">
    <property name="maxResults" value="${results.max}"/>
</bean>

Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations).因为 PersonDaoImpl 在 Spring XML 文件中没有特征(它是通过注释从类路径中提取的)。 I've got as far as the following:我有以下几点:

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {

    @Resource(name = "propertyConfigurer")
    protected void setProperties(PropertyPlaceholderConfigurer ppc) {
    // Now how do I access results.max? 
    }
}

But it's not clear to me how I access the property I'm interested in from ppc ?但我不清楚如何从ppc访问我感兴趣的财产?

I have a bunch of Spring beans which are picked up from the classpath via annotations, eg我有一堆 Spring bean,它们是通过注释从类路径中提取的,例如

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
    // Implementation omitted
}

In the Spring XML file, there's a PropertyPlaceholderConfigurer defined:在 Spring XML 文件中,定义了一个PropertyPlaceholderConfigurer

<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/app.properties" />
</bean> 

I want to inject one of the properties from app.properites into the bean shown above.我想将 app.properites 中的一个属性注入到上面显示的 bean 中。 I can't simply do something like我不能简单地做类似的事情

<bean class="com.example.PersonDaoImpl">
    <property name="maxResults" value="${results.max}"/>
</bean>

Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations).因为 PersonDaoImpl 在 Spring XML 文件中没有特征(它是通过注释从类路径中提取的)。 I've got as far as the following:我有以下几点:

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {

    @Resource(name = "propertyConfigurer")
    protected void setProperties(PropertyPlaceholderConfigurer ppc) {
    // Now how do I access results.max? 
    }
}

But it's not clear to me how I access the property I'm interested in from ppc ?但我不清楚如何从ppc访问我感兴趣的财产?

I have a bunch of Spring beans which are picked up from the classpath via annotations, eg我有一堆 Spring bean,它们是通过注释从类路径中提取的,例如

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
    // Implementation omitted
}

In the Spring XML file, there's a PropertyPlaceholderConfigurer defined:在 Spring XML 文件中,定义了一个PropertyPlaceholderConfigurer

<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/app.properties" />
</bean> 

I want to inject one of the properties from app.properites into the bean shown above.我想将 app.properites 中的一个属性注入到上面显示的 bean 中。 I can't simply do something like我不能简单地做类似的事情

<bean class="com.example.PersonDaoImpl">
    <property name="maxResults" value="${results.max}"/>
</bean>

Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations).因为 PersonDaoImpl 在 Spring XML 文件中没有特征(它是通过注释从类路径中提取的)。 I've got as far as the following:我有以下几点:

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {

    @Resource(name = "propertyConfigurer")
    protected void setProperties(PropertyPlaceholderConfigurer ppc) {
    // Now how do I access results.max? 
    }
}

But it's not clear to me how I access the property I'm interested in from ppc ?但我不清楚如何从ppc访问我感兴趣的财产?

I have a bunch of Spring beans which are picked up from the classpath via annotations, eg我有一堆 Spring bean,它们是通过注释从类路径中提取的,例如

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
    // Implementation omitted
}

In the Spring XML file, there's a PropertyPlaceholderConfigurer defined:在 Spring XML 文件中,定义了一个PropertyPlaceholderConfigurer

<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/app.properties" />
</bean> 

I want to inject one of the properties from app.properites into the bean shown above.我想将 app.properites 中的一个属性注入到上面显示的 bean 中。 I can't simply do something like我不能简单地做类似的事情

<bean class="com.example.PersonDaoImpl">
    <property name="maxResults" value="${results.max}"/>
</bean>

Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations).因为 PersonDaoImpl 在 Spring XML 文件中没有特征(它是通过注释从类路径中提取的)。 I've got as far as the following:我有以下几点:

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {

    @Resource(name = "propertyConfigurer")
    protected void setProperties(PropertyPlaceholderConfigurer ppc) {
    // Now how do I access results.max? 
    }
}

But it's not clear to me how I access the property I'm interested in from ppc ?但我不清楚如何从ppc访问我感兴趣的财产?

I have a bunch of Spring beans which are picked up from the classpath via annotations, eg我有一堆 Spring bean,它们是通过注释从类路径中提取的,例如

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
    // Implementation omitted
}

In the Spring XML file, there's a PropertyPlaceholderConfigurer defined:在 Spring XML 文件中,定义了一个PropertyPlaceholderConfigurer

<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/app.properties" />
</bean> 

I want to inject one of the properties from app.properites into the bean shown above.我想将 app.properites 中的一个属性注入到上面显示的 bean 中。 I can't simply do something like我不能简单地做类似的事情

<bean class="com.example.PersonDaoImpl">
    <property name="maxResults" value="${results.max}"/>
</bean>

Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations).因为 PersonDaoImpl 在 Spring XML 文件中没有特征(它是通过注释从类路径中提取的)。 I've got as far as the following:我有以下几点:

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {

    @Resource(name = "propertyConfigurer")
    protected void setProperties(PropertyPlaceholderConfigurer ppc) {
    // Now how do I access results.max? 
    }
}

But it's not clear to me how I access the property I'm interested in from ppc ?但我不清楚如何从ppc访问我感兴趣的财产?

I have a bunch of Spring beans which are picked up from the classpath via annotations, eg我有一堆 Spring bean,它们是通过注释从类路径中提取的,例如

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
    // Implementation omitted
}

In the Spring XML file, there's a PropertyPlaceholderConfigurer defined:在 Spring XML 文件中,定义了一个PropertyPlaceholderConfigurer

<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/app.properties" />
</bean> 

I want to inject one of the properties from app.properites into the bean shown above.我想将 app.properites 中的一个属性注入到上面显示的 bean 中。 I can't simply do something like我不能简单地做类似的事情

<bean class="com.example.PersonDaoImpl">
    <property name="maxResults" value="${results.max}"/>
</bean>

Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations).因为 PersonDaoImpl 在 Spring XML 文件中没有特征(它是通过注释从类路径中提取的)。 I've got as far as the following:我有以下几点:

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {

    @Resource(name = "propertyConfigurer")
    protected void setProperties(PropertyPlaceholderConfigurer ppc) {
    // Now how do I access results.max? 
    }
}

But it's not clear to me how I access the property I'm interested in from ppc ?但我不清楚如何从ppc访问我感兴趣的财产?

I have a bunch of Spring beans which are picked up from the classpath via annotations, eg我有一堆 Spring bean,它们是通过注释从类路径中提取的,例如

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
    // Implementation omitted
}

In the Spring XML file, there's a PropertyPlaceholderConfigurer defined:在 Spring XML 文件中,定义了一个PropertyPlaceholderConfigurer

<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/app.properties" />
</bean> 

I want to inject one of the properties from app.properites into the bean shown above.我想将 app.properites 中的一个属性注入到上面显示的 bean 中。 I can't simply do something like我不能简单地做类似的事情

<bean class="com.example.PersonDaoImpl">
    <property name="maxResults" value="${results.max}"/>
</bean>

Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations).因为 PersonDaoImpl 在 Spring XML 文件中没有特征(它是通过注释从类路径中提取的)。 I've got as far as the following:我有以下几点:

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {

    @Resource(name = "propertyConfigurer")
    protected void setProperties(PropertyPlaceholderConfigurer ppc) {
    // Now how do I access results.max? 
    }
}

But it's not clear to me how I access the property I'm interested in from ppc ?但我不清楚如何从ppc访问我感兴趣的财产?

I have a bunch of Spring beans which are picked up from the classpath via annotations, eg我有一堆 Spring bean,它们是通过注释从类路径中提取的,例如

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
    // Implementation omitted
}

In the Spring XML file, there's a PropertyPlaceholderConfigurer defined:在 Spring XML 文件中,定义了一个PropertyPlaceholderConfigurer

<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/app.properties" />
</bean> 

I want to inject one of the properties from app.properites into the bean shown above.我想将 app.properites 中的一个属性注入到上面显示的 bean 中。 I can't simply do something like我不能简单地做类似的事情

<bean class="com.example.PersonDaoImpl">
    <property name="maxResults" value="${results.max}"/>
</bean>

Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations).因为 PersonDaoImpl 在 Spring XML 文件中没有特征(它是通过注释从类路径中提取的)。 I've got as far as the following:我有以下几点:

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {

    @Resource(name = "propertyConfigurer")
    protected void setProperties(PropertyPlaceholderConfigurer ppc) {
    // Now how do I access results.max? 
    }
}

But it's not clear to me how I access the property I'm interested in from ppc ?但我不清楚如何从ppc访问我感兴趣的财产?

I have a bunch of Spring beans which are picked up from the classpath via annotations, eg我有一堆 Spring bean,它们是通过注释从类路径中提取的,例如

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
    // Implementation omitted
}

In the Spring XML file, there's a PropertyPlaceholderConfigurer defined:在 Spring XML 文件中,定义了一个PropertyPlaceholderConfigurer

<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/app.properties" />
</bean> 

I want to inject one of the properties from app.properites into the bean shown above.我想将 app.properites 中的一个属性注入到上面显示的 bean 中。 I can't simply do something like我不能简单地做类似的事情

<bean class="com.example.PersonDaoImpl">
    <property name="maxResults" value="${results.max}"/>
</bean>

Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations).因为 PersonDaoImpl 在 Spring XML 文件中没有特征(它是通过注释从类路径中提取的)。 I've got as far as the following:我有以下几点:

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {

    @Resource(name = "propertyConfigurer")
    protected void setProperties(PropertyPlaceholderConfigurer ppc) {
    // Now how do I access results.max? 
    }
}

But it's not clear to me how I access the property I'm interested in from ppc ?但我不清楚如何从ppc访问我感兴趣的财产?

I have a bunch of Spring beans which are picked up from the classpath via annotations, eg我有一堆 Spring bean,它们是通过注释从类路径中提取的,例如

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
    // Implementation omitted
}

In the Spring XML file, there's a PropertyPlaceholderConfigurer defined:在 Spring XML 文件中,定义了一个PropertyPlaceholderConfigurer

<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/app.properties" />
</bean> 

I want to inject one of the properties from app.properites into the bean shown above.我想将 app.properites 中的一个属性注入到上面显示的 bean 中。 I can't simply do something like我不能简单地做类似的事情

<bean class="com.example.PersonDaoImpl">
    <property name="maxResults" value="${results.max}"/>
</bean>

Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations).因为 PersonDaoImpl 在 Spring XML 文件中没有特征(它是通过注释从类路径中提取的)。 I've got as far as the following:我有以下几点:

@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {

    @Resource(name = "propertyConfigurer")
    protected void setProperties(PropertyPlaceholderConfigurer ppc) {
    // Now how do I access results.max? 
    }
}

But it's not clear to me how I access the property I'm interested in from ppc ?但我不清楚如何从ppc访问我感兴趣的财产?

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

相关问题 如何将属性值注入到已配置注释的Spring MVC 3.0控制器中 - How can I inject a property value into an annotation configured spring mvc 3.0 controller 如何将Spring bean ID注入另一个Spring Configured Bean? - How to inject a Spring bean id into another Spring Configured Bean? 我如何制作一个可以在设置器和构造函数依赖项中配置的Spring bean? - How can i make a Spring bean which can be configured in setters as well constructor dependency? 确定哪些Spring @Value注释无法注入 - Determining Which Spring @Value Annotations Fail To Inject 使用Spring,如何将子bean注入父bean? - With Spring, how can I inject a child bean in a parent bean? 如何使用Spring注释将Properties文件中的值注入到现有实例(不受Spring管理)的字段中? - How do I inject a value from Properties file to a field of an existing instance (not managed by Spring) using Spring annotations? 使用注解将JSF请求参数注入到Spring管理的bean中 - Inject JSF request parameter in a bean managed by Spring using annotations 如何在 spring bean 中注入字符串属性 - How to inject String property in a spring bean 如何创建可以使用注释自动装配的 spring bean? - How to create spring bean that can be autowired using annotations? 如何在测试中注入bean的属性源 - How can I inject property source of a bean in test
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM