Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8278819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:07:48+00:00 2026-06-08T09:07:48+00:00

I have a simple Spring Bean Expression, which evaluates fine when I define it

  • 0

I have a simple Spring Bean Expression, which evaluates fine when I define it inside an application context file:

<bean id="myConfigBean" class="com.example.myBeanConfigBean">
    <property name="myProperty" value="#{ someOtherBean.getData() }"/>
</bean>

Now, I want to do the same evaluation programmatically. I have used the following code:

final ExpressionParser parser = new SpelExpressionParser();
final TemplateParserContext templateContext = new TemplateParserContext();
Expression expression = parser.parseExpression("#{ someOtherBean.getData() }", templateContext);
final String value = (String) expression.getValue();

This throws an exception:

EL1007E:(pos 22): Field or property 'someOtherBean' cannot be found on null

I guess I have to set a root object somehow that allows to the configured beans like a property. But I did not get it to work yet. Anyone, who has done this already and could give a hint?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:07:49+00:00Added an answer on June 8, 2026 at 9:07 am

    implement BeanFactoryAware to get a reference to the bean factory; then…

    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setBeanResolver(new BeanFactoryResolver(this.beanFactory));
    Expression expression = parser.parseExpression("@someOtherBean.getData()"); 
    // or "@someOtherBean.data"
    final String value = expression.getValue(context, String.class);
    

    EDIT

    To answer the comment below. The @ triggers the use of the bean factory resolver to access a bean; an alternative is to add a BeanExpressionContextAccessor to the evaluation context and use a BeanExpressionContext as the root object for the evaluation…

    final ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setBeanResolver(new BeanFactoryResolver(beanFactory));
    context.addPropertyAccessor(new BeanExpressionContextAccessor());
    Expression expression = parser.parseExpression("someOtherBean.getData()");
    BeanExpressionContext rootObject = new BeanExpressionContext(beanFactory, null);
    
    ...
    
    String value = expression.getValue(context, rootObject, String.class);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following simple expression in my application-context.xml: <bean id=instrument class=com.ustunozgur.Instrument init-method=initialize scope=prototype>
Hello all I have a simple Spring application which will not end as there
I have a simple Spring & Jersey application, which works perfectly well for consuming
I have the following class (from a simple Spring tutorial) public class CarValidator implements
I have an extremely simple web application running in Tomcat using Spring 3.0.2, Hibernate
Assume we have a simple @Configuration : @Configuration public class FooBarConfiguration { @Bean public
I have a simple class that has a property called executor in which I'd
I have a pretty simple JSP/Servlet 3.0/Spring MVC 3.1 application. On one of my
I have the following spring configuration: <context:component-scan base-package=uk.co.mysite.googlecontactsync.aop/> <bean name=simpleEmailSender class=uk.co.mysite.util.email.simple.SimpleEmailSenderImplementation/> <aop:aspectj-autoproxy/> Then I
I have a simple Spring MVC application that looks up some user details from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.