How to call super constructor with params from abstract class if current class is spring bean?

Mil :

I have two classes from custom library, that i can't change. Bass class have only constructor with custom param, that's not a bean. I want to pass param via child constructor, but i have no idea how to do that, so please help)

I tried this, but doesn't work. Idea underline param in Child constructor.

@Bean
public ChildClass childClass() {
    return new ChildClass(new CustomParam(5));
}

Base class- can't use @Component, that class from library

public abstract class BaseClass {

private CustomParam customParam;

protected BaseClass(CustomParam customParam) {
    this.customParam = customParam;
}

public Integer getCustomParam() {
    return customParam.getParamValue();
}
}

Child class. My own extension

@Component
public class ChildClass extends BaseClass {

//idea underline customParam "could not autowire"
public ChildClass(CustomParam customParam) {
    super(customParam);
}
}

Param class- can't use @Component, that class from library

public class CustomParam {
private Integer paramValue;

public CustomParam(Integer paramValue) {
    this.paramValue = paramValue;
}

public Integer getParamValue() {
    return paramValue;
}

public void setParamValue(Integer paramValue) {
    this.paramValue = paramValue;
}
}
Deadpool :

CustomParam need not to be annotated with @Component annotation, still you can declare it as bean using@Bean annotation

Config class

@Bean
public ChildClass childClass() {
    return new ChildClass(customParam());
 }

  @Bean
public CustomParam customParam() {
    return new CustomParam(5);
 }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Call constructor in an abstract class

From Dev

How to call a super constructor from another inherited class?

From Dev

How to call the constructor of an Abstract class from another constructor inside the same class (method overloading)

From Java

How to create a Spring bean from a static inner class constructor?

From Dev

Call constructor in abstract class with generics

From Java

How to call abstract method from abstract class called by inherit class

From Dev

How to use SUPER class while extending it from an Abstract class

From Dev

Abstract class with constructor, force inherited class to call it

From

Call super class constructor in Kotlin, Super is not an expression

From Dev

What happens if I remove the super constructor call from class file?

From Dev

How does abstract class call get a child value in constructor?

From Dev

How do I simulate an abstract class and call its constructor?

From Java

Is it valid to call an abstract method on the super class in java

From Java

what happen when somebody calls super in constructor of a class that inherit from abstract class?

From Java

How to call super method from grandchild class?

From Dev

Why can't we call super class constructor using super keyword from child class method in Java?

From Java

How to ensure that child class will call the correct super constructor in lombok?

From Dev

How to use the super keyword in this code to call the constructor of the parent class?

From Dev

Create constructor for class that inherits from abstract class

From Dev

Derived Class Constructor from an Abstract Class

From Dev

How scala compiler invoking abstract method from super class?

From Dev

How to delete an a sub object from an abstract super class in Entity Framework?

From Dev

How would I call a constructor of an abstract class inside of an extending class constructor

From Dev

java call method in constructor and abstract class?

From Dev

Abstract class constructor call overridable method

From Dev

How to override abstract class constructor in sub class

From Dev

How to call base class method from super class method

From Dev

How to call outer class' super method from inner class in Kotlin?

From Dev

How to call function from the constructor of a JS class

Related Related

  1. 1

    Call constructor in an abstract class

  2. 2

    How to call a super constructor from another inherited class?

  3. 3

    How to call the constructor of an Abstract class from another constructor inside the same class (method overloading)

  4. 4

    How to create a Spring bean from a static inner class constructor?

  5. 5

    Call constructor in abstract class with generics

  6. 6

    How to call abstract method from abstract class called by inherit class

  7. 7

    How to use SUPER class while extending it from an Abstract class

  8. 8

    Abstract class with constructor, force inherited class to call it

  9. 9

    Call super class constructor in Kotlin, Super is not an expression

  10. 10

    What happens if I remove the super constructor call from class file?

  11. 11

    How does abstract class call get a child value in constructor?

  12. 12

    How do I simulate an abstract class and call its constructor?

  13. 13

    Is it valid to call an abstract method on the super class in java

  14. 14

    what happen when somebody calls super in constructor of a class that inherit from abstract class?

  15. 15

    How to call super method from grandchild class?

  16. 16

    Why can't we call super class constructor using super keyword from child class method in Java?

  17. 17

    How to ensure that child class will call the correct super constructor in lombok?

  18. 18

    How to use the super keyword in this code to call the constructor of the parent class?

  19. 19

    Create constructor for class that inherits from abstract class

  20. 20

    Derived Class Constructor from an Abstract Class

  21. 21

    How scala compiler invoking abstract method from super class?

  22. 22

    How to delete an a sub object from an abstract super class in Entity Framework?

  23. 23

    How would I call a constructor of an abstract class inside of an extending class constructor

  24. 24

    java call method in constructor and abstract class?

  25. 25

    Abstract class constructor call overridable method

  26. 26

    How to override abstract class constructor in sub class

  27. 27

    How to call base class method from super class method

  28. 28

    How to call outer class' super method from inner class in Kotlin?

  29. 29

    How to call function from the constructor of a JS class

HotTag

Archive