[
https://issues.apache.org/jira/browse/CAMEL-12683?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16556242#comment-16556242
]
Christian Ribeaud commented on CAMEL-12683:
-------------------------------------------
[~zregvart]: I am NOT talking about accessing bean properties when
building/setting new routes. My concern is more about accessing registry
entries by using '*#*', in a route URI for instance. Lets take a concrete
example:
[This|http://camel.apache.org/jpa.html] documentation page is telling me that I
could specify a *JPA* URI like following one:
{code:java}
from("jpa://myGreatJpaEntity?consumer.namedQuery={{spring.jpa.namedQuery}}&consumer.parameters=#namedQueryParameters&maximumResults={{prodic.jpa.maximumResults}}&consumeLockEntity=false&delay=20000&greedy=true")...
{code}
Names within curly braces are *Spring* properties and names starting with '*#*'
are registry entries (by the way, up to the documentation,
{{consumer.parameters}} can only be registry entries). So, if I have a *Spring*
bean named _namedQueryParameters_, everything is working fine. BUT, if I want
to access one of the properties of my bean (something like
{{...&consumer.parameters=#namedQueryProperties.parameters}}), then this will
NOT work (because the support for {{#}} is very limited).
Do you see now what I'm meaning?
> When lookup the registry, Camel should support more complex expressions like
> 'myBean.property'
> ----------------------------------------------------------------------------------------------
>
> Key: CAMEL-12683
> URL: https://issues.apache.org/jira/browse/CAMEL-12683
> Project: Camel
> Issue Type: Improvement
> Components: camel-spring
> Affects Versions: 2.21.1
> Reporter: Christian Ribeaud
> Assignee: Zoran Regvart
> Priority: Major
>
> Currently, only simple *Spring* beans lookup is supported, like {{#myBean}}.
> Deeper lookup is currently not supported. As a workaround, you could specify
> several *Spring* beans which then maps to the properties of the original bean.
> Following code snipped would, for instance, make possible more complex
> queries:
> {code:java}
> public class MyApplicationContextRegistry extends ApplicationContextRegistry {
> private final BeanResolver beanResolver;
> private final PropertyAccessor propertyAccessor;
> private final BeanExpressionContext beanExpressionContext;
> MyApplicationContextRegistry(ApplicationContext applicationContext) {
> super(applicationContext);
> beanResolver = new BeanFactoryResolver(applicationContext);
> propertyAccessor = new BeanExpressionContextAccessor();
> beanExpressionContext = createExpressionContext(applicationContext);
> }
> @Override
> public Object lookupByName(final String name) {
> assert name != null : "Unspecified name";
> final ExpressionParser parser = new SpelExpressionParser();
> Expression expression = parser.parseExpression(name);
> Object expressionValue =
> expression.getValue(createEvaluationContext(), beanExpressionContext);
> return expressionValue;
> }
> private static BeanExpressionContext
> createExpressionContext(ApplicationContext applicationContext) {
> assert applicationContext instanceof ConfigurableApplicationContext :
> String.format("MUST be an instance of '%s'.",
> ConfigurableApplicationContext.class.getName());
> ConfigurableBeanFactory configurableBeanFactory =
> ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
> return new BeanExpressionContext(configurableBeanFactory, null);
> }
> private EvaluationContext createEvaluationContext() {
> StandardEvaluationContext context = new StandardEvaluationContext();
> context.setBeanResolver(beanResolver);
> context.addPropertyAccessor(propertyAccessor);
> return context;
> }
> }
> {code}
> And this code uses _out-of-the-box_ *Spring* functionalities (I think...).
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)