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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:59:50+00:00 2026-06-13T18:59:50+00:00

I am trying to use the bean created in the spring Container in the

  • 0

I am trying to use the bean created in the spring Container in the JSF ManagedBean using @ManagedProperty annotation.But I am getting null pointer when using that bean.Once I start my server I can see my beans are created Here

Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@9d532ae: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,userBean,userService];

HomepageBean.java

package come.test.backingbean

 @ManagedBean
    @sessionScoped

        public Class HomepageBean{

        @ManagedProperty(value="#{userBean}")
        private UserBean userBean;// getters and setters


       public String doLogin() {
            String url = "login.xhtml";
            LoginBean manager = new LoginBean();  // This bean has a condition which check for Username and password entered by user.
            if (manager.auth(username, password)) {
                isLoggedIn = true;
                url = "homepage";
                String username=sample;
                userBean.getUserInfo(username);
            } else {
                FacesContext context = FacesContext.getCurrentInstance();
                context.addMessage(username, new FacesMessage(
                        "Invalid Username and or Password"));
            }
            return url;
        }

UserBean.java

package com.test.mypackage

@Component
Public Class UserBean{

@Autowired
private UserService userServie  // getters and setters.

     public void getUserInfo(String userId){
      userService.findByUserId(userId)
 }
}
}

UserService.java

package com.test.service;

public interface UserService {

    public void save(User User);
    public void update(User user);
    public void delete(User user);
    public User findByUserId(String userId);

}

I can see when my server started the bean I am trying to use is pre-instantiated.I am defining my applicationContext.xml in web.xml as a Context-param. And I am defining all the beans in my Spring.xml like this

spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<context:annotation-config />

<context:component-scan base-package="com.test" />

<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>

</beans> 

which is in my class path and importing that as a resource in applicationContext.xml.

applicationContext.xml

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:security="http://www.springframework.org/schema/security"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <import resource="classpath:database/DataSource.xml" />

    <import resource="classpath:database/Hibernate.xml" />

   <import resource="classpath:config/Spring.xml" />

</beans>

my faces-confi.xml

<application>
   <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
    <resource-bundle>
        <base-name>com.test.boundles.messages</base-name>
        <var>msg</var>
    </resource-bundle>
    </application>

Any problem with my approach.

  • 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-13T18:59:52+00:00Added an answer on June 13, 2026 at 6:59 pm

    There are multiple things that should have been handled better.

    1) You just need <context:component-scan base-package="com.test" />, remove annotation-config and AutowiredAnnotationBeanPostProcessor.

    See Reason: Difference between <context:annotation-config> vs <context:component-scan>
    and Documentation

    2) You do not have scope on your UserBean, if you do not mention any scope the default scope will be Singleton which I do not think is desirable in this context.

    3) You are trying to use an interface instead of an instantiable class that implements this interface.

    4) You should then mark the implementation class with @Service to be autowired.

    5) I hope you have getters and setters instead of just those comments.

    For a good example refer to this link

    See also:

    • @Scope("request") not working
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use the Spring Framework IoC Container to create an instance
First off, I think I'm trying to use Spring incorrectly, but confirmation would be
I'm trying to inject Spring beans into an EJB using @Interceptors(SpringBeanAutowiringInterceptor.class) but I cannot
trying to use this route: from(activemq:profiles).aggregate(header(cheese)).batchSize(30).bean(ProfilesQueueService, saveContacts) Fails with: No signature of method: org.apache.camel.model.RouteType.aggregate()
is springdoclet use to generate bean defination xml files? servlet-config.xml..etc ? i trying to
I'm trying to use a Spring context namespace to build some existing configuration objects
I'm trying to create a multiaction web controller using Spring annotations. This controller will
i am trying to decalre a spring bean on a xml (Mule config file),
I am trying to create a Java EE Web Application with JSF 2, Spring
I'm creating a JSF 2-application and I'm trying to use form validation in 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.