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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:39:42+00:00 2026-06-04T20:39:42+00:00

I am just dabbling with Spring framework. Here I was trying out the parent

  • 0

I am just dabbling with Spring framework. Here I was trying out the “parent” attribute in the bean declaration,

This is my code below for CommonCar.java:

package com.justPractise.ex01;

public class CommonCar {
    private String modelName;
    private String engine;

    public CommonCar(String modelName){
        this.modelName = modelName;
        System.out.println(" PARAMETERISED "+this.getClass().getName()+" INITIALISED..... ");
    }

    public CommonCar(){
        System.out.println(this.getClass().getName()+" INITIALISED..... ");
    }

    public String getModelName() {
        return modelName;
    }

    public void setModelName(String modelName) {
        this.modelName = modelName;
    }

    public String getEngine() {
        return engine;
    }

    public void setEngine(String engine) {
        this.engine = engine;
    }

    @Override
    public String toString(){
        StringBuffer strb = new StringBuffer();
        strb.append("\nDEFAULT CAR ");
        strb.append(this.modelName);
        strb.append("\nENGINE NAME ");
        strb.append(this.engine);
        return strb.toString();     
    }

}

This the code below for CustomCar.java:

package com.justPractise.ex01;

public class CustomCar {
    private String modelName;
    private String engine;

    public CustomCar(){
        System.out.println(this.getClass().getName()+" INITIALISED..... ");
    }

    public String getModelName() {
        return modelName;
    }



    public void setModelName(String modelName) {
        this.modelName = modelName;
    }

    public String getEngine() {
        return engine;
    }

    public void setEngine(String engine) {
        this.engine = engine;
    }



    @Override
    public String toString(){
        StringBuffer strb = new StringBuffer();
        strb.append("\nDEFAULT CAR ");
        strb.append(this.modelName);
        strb.append("\nENGINE NAME ");
        strb.append(this.engine);
        return strb.toString();     
    }
}

This is the bean-jojo.xml file:

<?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" default-lazy-init="true">

         <bean class="com.justPractise.ex01.CommonCar" id="commonCAR">
            <constructor-arg value="TATA-SAFARI V30" />
            <property name="engine" value="2340 CC FOUR CYLINDER 1700 BHP ENGINE" />
         </bean>

         <bean class="com.justPractise.ex01.CustomCar" id="customCAR" parent="commonCAR">
            <property name="modelName" value="TOYOTA-INNOVA" />         
         </bean>                    

</beans>

This is the class with the main method, which I run from commandline:

package com.justPractise.ex01;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainPractise01 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        ApplicationContext ctx = null;  
        CustomCar obj = null;
        try{
            ctx = new ClassPathXmlApplicationContext("bean-jojo.xml");
            obj = (CustomCar) ctx.getBean("customCAR"); 
            System.out.println(obj);                        
        }catch(Exception e){
            e.printStackTrace();            
        }
    }

}

Now if I run the above programme, I get this error in the command prompt:

[java] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customCAR' defined in class path resource
[bean-jojo.xml]: 1 constructor arguments specified but no matching constructor found in bean 'customCAR' (hint: specify index/type/name 
arguments for simple parameters to avoid type ambiguities)

But if I make the following changes to the bean-jojo.xml, my programme runs fine:

 <bean class="com.justPractise.ex01.CommonCar" id="commonCAR">
            <property name="modelName" value="TATA-SAFARI V30" />
            <property name="engine" value="2340 CC FOUR CYLINDER 1700 BHP ENGINE" />
         </bean>

This is the expected output I get by making the above change in xml:

[java] com.justPractise.ex01.CustomCar INITIALISED.....
[java]
[java] DEFAULT CAR TOYOTA-INNOVA
[java] ENGINE NAME 2340 CC FOUR CYLINDER 1700 BHP ENGINE
[echo] Java running completed

So, can you tell me why constructor args in the CommonCar declaration in bean-jojo.xml was not working?
Waiting for the comments

  • 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-04T20:39:43+00:00Added an answer on June 4, 2026 at 8:39 pm

    The exception could not be more readable. Create a constructor in your customBean car that accepts a String (Spring will pass it TATA-SAFARI V30)

    Your second example works because you no longer reference the commonClass superclass, so it is not defined a constructor with a parameter

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

Sidebar

Related Questions

just wanted to add this Color Picker ( http://code.google.com/p/devmil-android-color-picker/source/browse/ ) to my app and
Just additional information: this is for a game project I'm working on. I'm trying
Morning folks. Novice Rich here once again requesting assistance. I have just started dabbling
Just starting to figure Python out. I've read this question and its responses: Is
Just wondering what code I would need to do this?
Just dabbling in some Objective-C and I found this statement quite intriguing: self =
Just wondering if anyone can help me with this slight issue. I'm writing a
So I've been dabbling around in the Appcelerator Titanium framework for the better part
For a new application I want to start dabbling in BDD and I'm trying
This is my first time dabbling in NLP so please excuse my ignorance. I'm

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.