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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:59:07+00:00 2026-05-23T06:59:07+00:00

There are many documentations out there on how to achieve this task but I

  • 0

There are many documentations out there on how to achieve this task but I still couldn’t resolve my issue. I’m new to working with servlet so I probably missed something.

I use red5 that uses tomcat 6 to create a servlet that uses a spring bean that’s of a MysqlDb class for database manipulations.

when I point to red5 using port 5080 it acts as a regular tomcat server and i can browse jsp and servlet pages.

my web.xml contains the following relevant information:

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

<servlet>
  <servlet-name>fbauth</servlet-name>
  <servlet-class>com.xpogames.FbAuth</servlet-class>
</servlet>

<servlet-mapping>
  <servlet-name>fbauth</servlet-name>
  <url-pattern>/fbauth</url-pattern>
</servlet-mapping>

my applicationContext.xml:

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

<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/red5-web.properties" />
</bean>

<bean id="idDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName"><value>${db.driver}</value></property>
    <property name="url"><value>${db.url}</value></property>
    <property name="username"><value>${db.username}</value></property>
    <property name="password"><value>${db.password}</value></property>
    <property name="poolPreparedStatements"><value>true</value></property>
    <property name="maxActive"><value>10</value></property>
    <property name="maxIdle"><value>10</value></property>
 </bean>
 
 <bean id="MysqlDb" class="com.xpogames.MysqlDb">
    <property name="idDataSource" ref="idDataSource"/>
 </bean>
 

</beans>

my FbAuth servlet:

package com.xpogames;

import java.io.IOException;

import java.io.PrintWriter;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class FbAuth extends HttpServlet {
private static final long serialVersionUID = 1L;
   
public FbAuth() {
    super();
    // TODO Auto-generated constructor stub
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    WebApplicationContext webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession().getServletContext());
    MysqlDb mysqlDb = (MysqlDb)webApplicationContext.getBean("MysqlDb");
    out.println(mysqlDb.testme());
    out.println("Hello, world!");
    out.close();        
}

}

I get the following error:

java.lang.IllegalStateException: Context attribute is not of type WebApplicationContext

I think I’m not fetching the spring bean correctly.

any ideas?

thank you!

update

this is my new init function:

public void init(ServletConfig config) throws ServletException {
    super.init(config);
     ServletContext servletContext = this.getServletContext();
    this._context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
}

thanks a lot! 🙂

  • 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-05-23T06:59:08+00:00Added an answer on May 23, 2026 at 6:59 am

    I use the following in the init() method of the servlet. The init() method is called only once in a Servlets lifecycle.

    ApplicationContext context = 
        WebApplicationContextUtils.getRequiredWebApplicationContext(
            this.getServletContext());
    

    Also, do you have the “contextConfigLocation” in your web.xml?

    <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:/**/spring-config.xml
            </param-value>
     </context-param>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are many tools out there for writing and managing requirements, but are there
I know there is alot of documentation out there on this stuff, but I
There are many ways of doing debugging, using a debugger is one, but the
There are many editions of Eclipse for Java development. I am trying out MyEclipse
Is there any sort of xml reference? I found this which turned out to
I know there is an Objective-C wrapper around YAJL, but this is a really
Sorry if this sounds stupid but I'm really new to LiftWeb and just struggling
I understand this question couldn't be more beginner, but I am having a hard
There are so many tools out there. You can do so much things around
In the installation documentation to RoR it mentions that there are many limitations to

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.