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

  • Home
  • SEARCH
  • 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 6048865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:30:40+00:00 2026-05-23T07:30:40+00:00

I have a web application that executes on tomcat 6. I have a MysqlDb

  • 0

I have a web application that executes on tomcat 6.

I have a MysqlDb class that uses a BasicDataSource from a spring JDBC.

so far I’ve used the following bean configuration in web.xml:

<bean id="MysqlDb" class="com.xpogames.gamesisland.mysql.MysqlDb">
    <property name="idDataSource" ref="idDataSource"/>
 </bean>

and I had the following setter function:

  public void setidDataSource(BasicDataSource ds) {
    this._dataSource=(DataSource)ds;
    this._simpleJdbcTemplate = new SimpleJdbcTemplate(_dataSource);
    this._jdbcTemplate = new JdbcTemplate(_dataSource);
 }

I want to convert my class to use static functions, so I created an empty private constructor so the class won’t explicitly instantiated by callers.

besides that I changed the setidDataSource function to a static function, but when I try to do that I get the following error:

Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property ‘idDataSource’ of bean class [com.xpogames.gamesisland.mysql.MysqlDb]: Bean property ‘idDataSource’ is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

is there a way to resolve this issue in web.xml or do I need to manually
fetch the ServletContext

ServletContext servletContext = this.getServletContext();
this._context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);

and fetch the bean from there and just remove the lines i printed here from web.xml ?

  • 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-23T07:30:41+00:00Added an answer on May 23, 2026 at 7:30 am

    I understand know that I had a bad implementation idea. I still need a constructor, so building a class with static functions and static init is a bad idea, and trying to execute a static setter from a bean is not logical and impossible.

    Instead I changed the class to be a singleton class, so I will be able to use it anywhere in my application and it will be constructed only once.

    thanks for all the information.

    update

    I still don’t know if that’s a good method, but at least it works.

    in my red-web.xml (consider it as spring applicationContext.xml), I have the following:

     <bean id="MysqlDb" class="com.xpogames.gamesisland.mysql.MysqlDb" init-method="getInstance">
        <property name="idDataSource" ref="idDataSource"/>
     </bean>
    

    Here it creates a MysqlDb bean and configure it to use the getInstance() init method if MysqlDb Class. i made sure to have a setidDataSource() function in mysqlDb class for the datasource to be properly set.

    <bean id="web.handler" class="com.xpogames.gamesisland.Application">
        <property name="MysqlDb" ref="MysqlDb"/>
    </bean>
    

    Here, I create the main bean of my application and I made sure to have the function setMysqlDb for the MysqlDb class to be set from the bean configuration.

    So far mysqlDb acts as a singelton class because it’s constructor is protected and it creates the instance only once:

    public static MysqlDb getInstance() {
        if (instance == null) {
            instance = new MysqlDb();
        }
        return instance;
    }
    

    The problem that I encountered was that in other parts of my application whenever I used getInstance(), the MysqlDb class would come up and all the variables that where set with setidDataSource where null.

    so resolve that issue I created another function called setInstance in mysqlDb:

    public static void setInstance(MysqlDb db) {
    instance=db;
    }

    this is my main setMysqlDb function in my main application:

    public void setMysqlDb(MysqlDb db) {
        this._mysqlDb=db;
        /* it seems that without forcing a setInstance on the class, whenever other classes
         * would try to getInstance(), variables that are supposed to be configured by the bean
         * would be empty. this resolves that issue
         */
        MysqlDb.setInstance(db);
    }
    

    so this configuration works. it’s obviously not the recommended or best solution! but it seems that I need to read and learn further before I come up with a better solution.

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

Sidebar

Related Questions

My colleague and I have a web application that uses Spring 3.0.0 and JPA
I have a web application that needs to take a file upload from the
I've been reading about Skip Lists lately. I have a web application that executes
I have a java web application that selects one column from table (with 6
I'm coding a web application in GWT. I have a class that handles all
I have a web application that should behave differently for internal users than external
I have a web application that is becoming rather large. I want to separate
I have this web application that has grown to an unmanageable mess. I want
I have a web application that's branded according to the user that's currently logged
I have a web application that allows a user to search on some criteria,

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.