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 8249579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:35:40+00:00 2026-06-07T23:35:40+00:00

I’m using Spring and JSF 2 to create a web application. The business objects

  • 0

I’m using Spring and JSF 2 to create a web application.
The business objects are kept in the Spring container, and I inject them in the Managed Beans using the @ManagedProperty, like this:

@ManagedBean
@ViewScoped
public class SomeMB implements Serializable {
    private static final long serialVersionUID = 1L;

    @Getter @Setter
    @ManagedProperty("#{someService}")
    private SomeService someService;
    // ...

The problem is, I keep getting a NotSerializableException for a class from Spring (ServiceLocatorFactoryBean) that it’s being used by the SomeService bean.

If I make it transient, how could I do the re-injection of it after deserializing?

Or, what would be other ways to solve this problem?

I’ve been reading several other questions similar here, but couldn’t find any that dealt exactly with this problem.

  • 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-07T23:35:42+00:00Added an answer on June 7, 2026 at 11:35 pm

    Instead of injecting the Spring beans via EL in a @ManagedProperty annotation (executed on the ManagedBean initialization), obtain the beans evaluating the EL at runtime.

    With this approach, this is what the JSF beans should look like:

    @ManagedBean
    @ViewScoped
    public class SomeMB implements Serializable {
        private static final long serialVersionUID = 1L;
    
        private static SomeService someService() {
            return SpringJSFUtil.getBean("someService");
        }
        // ...
    

    And the utility class SpringJSFUtil.java that gets the bean via EL:

    import javax.faces.context.FacesContext;
    
    public class SpringJSFUtil {
    
        public static <T> T getBean(String beanName) {
            if (beanName == null) {
                return null;
            }
            return getValue("#{" + beanName + "}");
        }
    
        @SuppressWarnings("unchecked")
        private static <T> T getValue(String expression) {
            FacesContext context = FacesContext.getCurrentInstance();
            return (T) context.getApplication().evaluateExpressionGet(context,
                    expression, Object.class);
        }
    }
    

    This eliminates the Spring bean property (at the cost of doing a few more EL evaluations), thus avoiding all the serialization issues of having the property in first place.

    The same approach, using OmniFaces:

    In my actual code, I use the evaluateExpressionGet(String expression) method of an utility class available from OmniFaces. So, for those of you who use it too, this is what my code really look like:

    import static org.omnifaces.util.Faces.evaluateExpressionGet;
    
    @ManagedBean
    @ViewScoped
    public class SomeMB implements Serializable {
        private static final long serialVersionUID = 1L;
    
        private static SomeService someService() {
            return evaluateExpressionGet("#{someService}");
        }
        // ...
    

    Notice that here the method gets the full EL (“#{expression}”), not just the Spring bean name (or you would get a ClassCastException).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.