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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:22:05+00:00 2026-05-30T13:22:05+00:00

Iam trying to pass dynamic argument values i.e username from request using spring ioc.But

  • 0

Iam trying to pass dynamic argument values i.e username from request using spring ioc.But iam unable to seen username value in userdaoimp.

UserDAOImpl.java

    public class UserDAOImpl implements UserDAO {
    private DataSource dataSource;
    private JdbcTemplate jdbctemplate;
    private String username;


    public void setUsername(String username) {
        this.username = username;
    }

    public DataSource getDataSource() {
        return dataSource;
    }

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
        this.jdbctemplate =new JdbcTemplate (dataSource);
    }




    public int getUserListSize() {
        System.out.println("UserDAOImpl::getUserListSize()"+username);
        int count=this.jdbctemplate.queryForInt("SELECT COUNT(*) FROM USER_INFO");
        return count;
    }

   }

epis.dao.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-2.5.xsd"> 



    <bean id="userdao" class="com.epis.dao.UserDAO">
        <property name="dataSource">
            <ref local="dataSource" />
        </property>
                <property name="username"/>
    </bean>
</beans>

UserService

enter image description here

enter image description here

  • 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-30T13:22:06+00:00Added an answer on May 30, 2026 at 1:22 pm

    In the XML you can assing properties only to the surrounding bean.

    so

    will not work, because UserService does not have a filed username and therefor the spring should not start.

    You can write it in two different ways:

    <bean id="userdao" class="com.epis.dao.UserDAO">
        <property name="dataSource" ref="dataSource" />
        <property name="username" value="aaa"/>
    </bean>
    
    <bean  ... class="...UserService">
        <property name="userdao" ref="userdao" />
    <bean>
    

    or

    <bean  ... class="...UserService">
        <property name="userdao">
            <bean class="com.epis.dao.UserDAO">
                <property name="dataSource" ref="dataSource" />
                <property name="username" value="aaa"/>
             </bean>
        </property>
    <bean>
    

    But you can not mix both styles for one property.


    Form the comment

    Actually my requirement is the username value is getting based on other business logic in UserService.This username will be forwarded into userdao constructor.How can I forward that value to userdao.

    This is not possible or at least not without a lot of handwritten magic. The reason is simple: The objects descriped in the XML file are created when the application starts, and the values are set while starting.

    But in general I think you can achieve your aim with some scoped beans. But I have highly doubt that scoped beans can be used for the database connection.

    I highly recommend to ask a new question hat focus on the dynamic requirement with the explanation you gave in the comment of this answer. (but without the bugy xml example) )

    @See Spring Reference Chapter 3.5 Bean scopes

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

Sidebar

Related Questions

I am trying to pass parameters from Visual Studio using VB.net to a Crystal
I am trying to pass a dataString to to an ajax call using JQuery.
I am trying to pass an XML list to a view but I am
I am trying to pass a number to my JavaScript function, but actually a
I am trying to pass a structure from C# into C++ library. I pass
I am trying to pass Eval to Html.RenderPartial inside ASP.NET Repeater but it does
I am trying to pass one variable to a jQuery function inline (i.e.: using
i am trying to pass in a selector into the ID variable but this
I am trying to pass data from SQL, to C#, then to an R
I am trying to pass a dynamic 2d array with bcast to all ranks.

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.