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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:22:02+00:00 2026-06-12T02:22:02+00:00

I want to use my Spring Beans in my JSF application, letting Spring inject

  • 0

I want to use my Spring Beans in my JSF application, letting Spring inject my services/repositories in my JSF Managed Beans.

I found a lot of solutions in the Internet, but the only one that worked was the following lines of code:

ApplicationContext ctx = FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());
albumRepository = (AlbumRepository) ctx.getBean("albumRepository");

albumRepository is the Spring Bean I’m trying to inject.

The problem is that it’s really lame, I don’t wanna do this in every class, for every injection. I’d like to use anotations, like “@Inject”.

Searching an answer in Google, I found that I should integrate JSF and Spring using the following config in faces-config.xml:

<application>
    <el-resolver>
        org.springframework.web.jsf.el.SpringBeanFacesELResolver
    </el-resolver>
</application>

Then, I should be able to use my Spring Beans with the annotation “@ManagedProperty(value=”#{albumRepository}”)”. I tried it, but I aways get the error “The property albumRepository for the managed bean does not exist”.

Searching again in Google I found out that I could use the Spring annotations to do my injections, the only thing i’d need would be to register the package where my managed beans are located in the applicationContext.xml. I’ve done it, but Spring just ignores my annotations (@Inject and @Autowired, I tried both).

After all these failures I tried to stop using the JSF annotations (@ManagedBean and @ViewScoped), instead, I used Spring ones (@Controller and @Scope). Now JSF doesn’t even recognize the beans.

What am I doing wrong?

Edit: My ApplicationContext.xml

<context:annotation-config/>
        <jpa:repositories base-package="com.ae.repository" />
        <context:component-scan base-package="com.ae.client.web, com.ae.service" />

        <!-- Data Source -->
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property>
            <property name="url"><value>jdbc:mysql://localhost:3306/academia</value></property>
            <property name="username"><value>root</value></property>
            <property name="password"><value>root</value></property>
        </bean>

        <bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="database" value="MYSQL" />
            <property name="showSql" value="true" />
        </bean>

        <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="dataSource" ref="dataSource" />
            <property name="jpaVendorAdapter" ref="jpaAdapter" />
            <property name="persistenceXmlLocation" value="/META-INF/persistence-web.xml"/>
        </bean>

        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
            <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>

Edit: My web.xml

<!-- Spring -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

    <!-- JSF -->
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>

    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>

    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>

    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>

    <!-- Primefaces -->
    <filter>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
  • 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-12T02:22:03+00:00Added an answer on June 12, 2026 at 2:22 am

    In your web.xml has context param like this ?

    <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:/*Context.xml</param-value>
        </context-param> 
    

    Also can you send listener about spring in your web.xml

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

Sidebar

Related Questions

i want to use 2 different beans (Spring) for one JSF-Page. I do not
I'm want to inject spring bean in JSF ManagedBean. Now I use: applicationContext.xml: <?xml
I want to use both ContextLoaderListener (so that I can pass Spring Beans to
I would like to use jsf annotations and some spring annotations to inject a
I have a bunch of java custom tags that use spring managed beans.. since
i want to to integrate spring jsf hibernate. i use maven and eclipse. but
I want to use Spring 3 for validation. In the reference documentation, section 6.2
I came from the Spring camp , I don't want to use Spring ,
I want to use two different Spring web contexts , each have own contextConfig,
I've recently started upgrading some applications to use Spring Webflow 2, and I want

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.