Spring - how to change propertyHow can I inject a property value into a Spring Bean which was configured using annotations?How to define a List bean in Spring?Injecting Mockito mocks into a Spring beanHow to import spring-config.xml of one project into spring-config.xml of another project?What's the difference between @Component, @Repository & @Service annotations in Spring?Spring Framework: Search Properties by NameHow to respond with HTTP 400 error in a Spring MVC @ResponseBody method returning String?Spring MVC form validation does't work for nested complex types(Spring, Thymeleaf) How to request to controller 'POST' with list of model inside a model?Spring bean properties configuration

Is tuition reimbursement a good idea if you have to stay with the job

Why didn't all the iron and heavier elements find their way to the center of the accretion disc in the early solar system?

How to properly use a function under a class?

Am I allowed to determine tenets of my contract as a warlock?

How to soundproof the Wood Shop?

I am caught when I was about to steal some candies

Why is it bad to use your whole foot in rock climbing

Harley Davidson clattering noise from engine, backfire and failure to start

Is all-caps blackletter no longer taboo?

How (un)safe is it to ride barefoot?

In American Politics, why is the Justice Department under the President?

Is Jesus the last Prophet?

Why is my Taiyaki (Cake that looks like a fish) too hard and dry?

Is it possible to have battery technology that can't be duplicated?

Are athlete's college degrees discounted by employers and graduate school admissions?

In Pandemic, why take the extra step of eradicating a disease after you've cured it?

If absolute velocity does not exist, how can we say a rocket accelerates in empty space?

Can I use 220 V outlets on a 15 ampere breaker and wire it up as 110 V?

ISP is not hashing the password I log in with online. Should I take any action?

Is it true that "only photographers care about noise"?

Fastest way from 8 to 7

When a class dynamically allocates itself at constructor, why does stack overflow happen instead of std::bad_alloc?

Why is the concept of the Null hypothesis associated with the student's t distribution?

What does BREAD stand for while drafting?



Spring - how to change property


How can I inject a property value into a Spring Bean which was configured using annotations?How to define a List bean in Spring?Injecting Mockito mocks into a Spring beanHow to import spring-config.xml of one project into spring-config.xml of another project?What's the difference between @Component, @Repository & @Service annotations in Spring?Spring Framework: Search Properties by NameHow to respond with HTTP 400 error in a Spring MVC @ResponseBody method returning String?Spring MVC form validation does't work for nested complex types(Spring, Thymeleaf) How to request to controller 'POST' with list of model inside a model?Spring bean properties configuration






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I have a class which I can't change:



public class A 
private String amountOfErrors;

public String getAmountOfErrors()
return amountOfErrors;


public void setAmountOfErrors(String amountOfErrors)
this.amountOfErrors = amountOfErrors;




bean which I can change:



<bean class="com.company.facades.A">
<property name="amountOfErrors" type="String"/>
</bean>


How can I change a type String to BigDecimal to call smth like that:



 A a = new A();
a.setAmountOfErrors(BigDecimal.ZERO)









share|improve this question






















  • no you cannot, maybe you can try like this a.setAmountOfErrors(BigDecimal.ZERO.toString()

    – Deadpool
    Mar 25 at 0:11











  • @Deadpool What if I added <property name="bigAmountOfErrors" type="BigDecimal"/>?

    – IVBORA
    Mar 25 at 0:23












  • you will get error during startup saying incompatible types

    – Deadpool
    Mar 25 at 0:24











  • @Deadpool Yes, true. And I need to extend class A with field bigAmountOfErrors. Maybe you know a mechanism to do this using spring?

    – IVBORA
    Mar 25 at 0:26







  • 1





    Hi! Then why not just do that? - you wouldn't even need to change the method name. You could just provide a version of the method with the same name but that takes a BigDecimal. Is it that you can't write ANY new Java code?

    – Steve
    Mar 25 at 0:27


















1















I have a class which I can't change:



public class A 
private String amountOfErrors;

public String getAmountOfErrors()
return amountOfErrors;


public void setAmountOfErrors(String amountOfErrors)
this.amountOfErrors = amountOfErrors;




bean which I can change:



<bean class="com.company.facades.A">
<property name="amountOfErrors" type="String"/>
</bean>


How can I change a type String to BigDecimal to call smth like that:



 A a = new A();
a.setAmountOfErrors(BigDecimal.ZERO)









share|improve this question






















  • no you cannot, maybe you can try like this a.setAmountOfErrors(BigDecimal.ZERO.toString()

    – Deadpool
    Mar 25 at 0:11











  • @Deadpool What if I added <property name="bigAmountOfErrors" type="BigDecimal"/>?

    – IVBORA
    Mar 25 at 0:23












  • you will get error during startup saying incompatible types

    – Deadpool
    Mar 25 at 0:24











  • @Deadpool Yes, true. And I need to extend class A with field bigAmountOfErrors. Maybe you know a mechanism to do this using spring?

    – IVBORA
    Mar 25 at 0:26







  • 1





    Hi! Then why not just do that? - you wouldn't even need to change the method name. You could just provide a version of the method with the same name but that takes a BigDecimal. Is it that you can't write ANY new Java code?

    – Steve
    Mar 25 at 0:27














1












1








1








I have a class which I can't change:



public class A 
private String amountOfErrors;

public String getAmountOfErrors()
return amountOfErrors;


public void setAmountOfErrors(String amountOfErrors)
this.amountOfErrors = amountOfErrors;




bean which I can change:



<bean class="com.company.facades.A">
<property name="amountOfErrors" type="String"/>
</bean>


How can I change a type String to BigDecimal to call smth like that:



 A a = new A();
a.setAmountOfErrors(BigDecimal.ZERO)









share|improve this question














I have a class which I can't change:



public class A 
private String amountOfErrors;

public String getAmountOfErrors()
return amountOfErrors;


public void setAmountOfErrors(String amountOfErrors)
this.amountOfErrors = amountOfErrors;




bean which I can change:



<bean class="com.company.facades.A">
<property name="amountOfErrors" type="String"/>
</bean>


How can I change a type String to BigDecimal to call smth like that:



 A a = new A();
a.setAmountOfErrors(BigDecimal.ZERO)






spring






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 0:08









IVBORAIVBORA

285




285












  • no you cannot, maybe you can try like this a.setAmountOfErrors(BigDecimal.ZERO.toString()

    – Deadpool
    Mar 25 at 0:11











  • @Deadpool What if I added <property name="bigAmountOfErrors" type="BigDecimal"/>?

    – IVBORA
    Mar 25 at 0:23












  • you will get error during startup saying incompatible types

    – Deadpool
    Mar 25 at 0:24











  • @Deadpool Yes, true. And I need to extend class A with field bigAmountOfErrors. Maybe you know a mechanism to do this using spring?

    – IVBORA
    Mar 25 at 0:26







  • 1





    Hi! Then why not just do that? - you wouldn't even need to change the method name. You could just provide a version of the method with the same name but that takes a BigDecimal. Is it that you can't write ANY new Java code?

    – Steve
    Mar 25 at 0:27


















  • no you cannot, maybe you can try like this a.setAmountOfErrors(BigDecimal.ZERO.toString()

    – Deadpool
    Mar 25 at 0:11











  • @Deadpool What if I added <property name="bigAmountOfErrors" type="BigDecimal"/>?

    – IVBORA
    Mar 25 at 0:23












  • you will get error during startup saying incompatible types

    – Deadpool
    Mar 25 at 0:24











  • @Deadpool Yes, true. And I need to extend class A with field bigAmountOfErrors. Maybe you know a mechanism to do this using spring?

    – IVBORA
    Mar 25 at 0:26







  • 1





    Hi! Then why not just do that? - you wouldn't even need to change the method name. You could just provide a version of the method with the same name but that takes a BigDecimal. Is it that you can't write ANY new Java code?

    – Steve
    Mar 25 at 0:27

















no you cannot, maybe you can try like this a.setAmountOfErrors(BigDecimal.ZERO.toString()

– Deadpool
Mar 25 at 0:11





no you cannot, maybe you can try like this a.setAmountOfErrors(BigDecimal.ZERO.toString()

– Deadpool
Mar 25 at 0:11













@Deadpool What if I added <property name="bigAmountOfErrors" type="BigDecimal"/>?

– IVBORA
Mar 25 at 0:23






@Deadpool What if I added <property name="bigAmountOfErrors" type="BigDecimal"/>?

– IVBORA
Mar 25 at 0:23














you will get error during startup saying incompatible types

– Deadpool
Mar 25 at 0:24





you will get error during startup saying incompatible types

– Deadpool
Mar 25 at 0:24













@Deadpool Yes, true. And I need to extend class A with field bigAmountOfErrors. Maybe you know a mechanism to do this using spring?

– IVBORA
Mar 25 at 0:26






@Deadpool Yes, true. And I need to extend class A with field bigAmountOfErrors. Maybe you know a mechanism to do this using spring?

– IVBORA
Mar 25 at 0:26





1




1





Hi! Then why not just do that? - you wouldn't even need to change the method name. You could just provide a version of the method with the same name but that takes a BigDecimal. Is it that you can't write ANY new Java code?

– Steve
Mar 25 at 0:27






Hi! Then why not just do that? - you wouldn't even need to change the method name. You could just provide a version of the method with the same name but that takes a BigDecimal. Is it that you can't write ANY new Java code?

– Steve
Mar 25 at 0:27













1 Answer
1






active

oldest

votes


















1














It depends somewhat on how you're injecting the bean. But basically just:



public class B extends A 
public void setAmountOfErrors(BigDecimal amountOfErrors)
this.amountOfErrors = amountOfErrors.toString();



<bean class="com.company.whatever.B">
<property name="amountOfErrors" type="BigDecimal"/>
</bean>


I'm actually not sure what you're trying to do with the property on either A or B. The main point is that you can create a B, but Spring will know it's an A and will inject it as an A where necessary.



But if you want to call the BigDecimal version of the setter from Java, you'll need to either inject it as a B or cast an injected A (that's really a B) to a B.






share|improve this answer























  • Does this make sense? What more can I do to try to help?

    – Steve
    Mar 25 at 0:35











  • Yes, it makes sense. Thanks!

    – IVBORA
    Mar 25 at 0:42











  • Glad I could help. I didn't think much about your line: <property name="amountOfErrors" type="String"/>. Thinking about it more, I realized that I didn't know the purpose of this line, and I don't think I've ever used one quite like this in my 10+ years of using Spring. I've used the 'value' and 'ref' attributes, but never 'type'. What do you think the purpose of this is? I'm not saying I know it has no purpose. I just can't think what that purpose is. Maybe you can teach me something :) - I also did some Googling, and couldn't find such a usage.

    – Steve
    Mar 25 at 1:05












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55329786%2fspring-how-to-change-property%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














It depends somewhat on how you're injecting the bean. But basically just:



public class B extends A 
public void setAmountOfErrors(BigDecimal amountOfErrors)
this.amountOfErrors = amountOfErrors.toString();



<bean class="com.company.whatever.B">
<property name="amountOfErrors" type="BigDecimal"/>
</bean>


I'm actually not sure what you're trying to do with the property on either A or B. The main point is that you can create a B, but Spring will know it's an A and will inject it as an A where necessary.



But if you want to call the BigDecimal version of the setter from Java, you'll need to either inject it as a B or cast an injected A (that's really a B) to a B.






share|improve this answer























  • Does this make sense? What more can I do to try to help?

    – Steve
    Mar 25 at 0:35











  • Yes, it makes sense. Thanks!

    – IVBORA
    Mar 25 at 0:42











  • Glad I could help. I didn't think much about your line: <property name="amountOfErrors" type="String"/>. Thinking about it more, I realized that I didn't know the purpose of this line, and I don't think I've ever used one quite like this in my 10+ years of using Spring. I've used the 'value' and 'ref' attributes, but never 'type'. What do you think the purpose of this is? I'm not saying I know it has no purpose. I just can't think what that purpose is. Maybe you can teach me something :) - I also did some Googling, and couldn't find such a usage.

    – Steve
    Mar 25 at 1:05
















1














It depends somewhat on how you're injecting the bean. But basically just:



public class B extends A 
public void setAmountOfErrors(BigDecimal amountOfErrors)
this.amountOfErrors = amountOfErrors.toString();



<bean class="com.company.whatever.B">
<property name="amountOfErrors" type="BigDecimal"/>
</bean>


I'm actually not sure what you're trying to do with the property on either A or B. The main point is that you can create a B, but Spring will know it's an A and will inject it as an A where necessary.



But if you want to call the BigDecimal version of the setter from Java, you'll need to either inject it as a B or cast an injected A (that's really a B) to a B.






share|improve this answer























  • Does this make sense? What more can I do to try to help?

    – Steve
    Mar 25 at 0:35











  • Yes, it makes sense. Thanks!

    – IVBORA
    Mar 25 at 0:42











  • Glad I could help. I didn't think much about your line: <property name="amountOfErrors" type="String"/>. Thinking about it more, I realized that I didn't know the purpose of this line, and I don't think I've ever used one quite like this in my 10+ years of using Spring. I've used the 'value' and 'ref' attributes, but never 'type'. What do you think the purpose of this is? I'm not saying I know it has no purpose. I just can't think what that purpose is. Maybe you can teach me something :) - I also did some Googling, and couldn't find such a usage.

    – Steve
    Mar 25 at 1:05














1












1








1







It depends somewhat on how you're injecting the bean. But basically just:



public class B extends A 
public void setAmountOfErrors(BigDecimal amountOfErrors)
this.amountOfErrors = amountOfErrors.toString();



<bean class="com.company.whatever.B">
<property name="amountOfErrors" type="BigDecimal"/>
</bean>


I'm actually not sure what you're trying to do with the property on either A or B. The main point is that you can create a B, but Spring will know it's an A and will inject it as an A where necessary.



But if you want to call the BigDecimal version of the setter from Java, you'll need to either inject it as a B or cast an injected A (that's really a B) to a B.






share|improve this answer













It depends somewhat on how you're injecting the bean. But basically just:



public class B extends A 
public void setAmountOfErrors(BigDecimal amountOfErrors)
this.amountOfErrors = amountOfErrors.toString();



<bean class="com.company.whatever.B">
<property name="amountOfErrors" type="BigDecimal"/>
</bean>


I'm actually not sure what you're trying to do with the property on either A or B. The main point is that you can create a B, but Spring will know it's an A and will inject it as an A where necessary.



But if you want to call the BigDecimal version of the setter from Java, you'll need to either inject it as a B or cast an injected A (that's really a B) to a B.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 25 at 0:32









SteveSteve

4,1381728




4,1381728












  • Does this make sense? What more can I do to try to help?

    – Steve
    Mar 25 at 0:35











  • Yes, it makes sense. Thanks!

    – IVBORA
    Mar 25 at 0:42











  • Glad I could help. I didn't think much about your line: <property name="amountOfErrors" type="String"/>. Thinking about it more, I realized that I didn't know the purpose of this line, and I don't think I've ever used one quite like this in my 10+ years of using Spring. I've used the 'value' and 'ref' attributes, but never 'type'. What do you think the purpose of this is? I'm not saying I know it has no purpose. I just can't think what that purpose is. Maybe you can teach me something :) - I also did some Googling, and couldn't find such a usage.

    – Steve
    Mar 25 at 1:05


















  • Does this make sense? What more can I do to try to help?

    – Steve
    Mar 25 at 0:35











  • Yes, it makes sense. Thanks!

    – IVBORA
    Mar 25 at 0:42











  • Glad I could help. I didn't think much about your line: <property name="amountOfErrors" type="String"/>. Thinking about it more, I realized that I didn't know the purpose of this line, and I don't think I've ever used one quite like this in my 10+ years of using Spring. I've used the 'value' and 'ref' attributes, but never 'type'. What do you think the purpose of this is? I'm not saying I know it has no purpose. I just can't think what that purpose is. Maybe you can teach me something :) - I also did some Googling, and couldn't find such a usage.

    – Steve
    Mar 25 at 1:05

















Does this make sense? What more can I do to try to help?

– Steve
Mar 25 at 0:35





Does this make sense? What more can I do to try to help?

– Steve
Mar 25 at 0:35













Yes, it makes sense. Thanks!

– IVBORA
Mar 25 at 0:42





Yes, it makes sense. Thanks!

– IVBORA
Mar 25 at 0:42













Glad I could help. I didn't think much about your line: <property name="amountOfErrors" type="String"/>. Thinking about it more, I realized that I didn't know the purpose of this line, and I don't think I've ever used one quite like this in my 10+ years of using Spring. I've used the 'value' and 'ref' attributes, but never 'type'. What do you think the purpose of this is? I'm not saying I know it has no purpose. I just can't think what that purpose is. Maybe you can teach me something :) - I also did some Googling, and couldn't find such a usage.

– Steve
Mar 25 at 1:05






Glad I could help. I didn't think much about your line: <property name="amountOfErrors" type="String"/>. Thinking about it more, I realized that I didn't know the purpose of this line, and I don't think I've ever used one quite like this in my 10+ years of using Spring. I've used the 'value' and 'ref' attributes, but never 'type'. What do you think the purpose of this is? I'm not saying I know it has no purpose. I just can't think what that purpose is. Maybe you can teach me something :) - I also did some Googling, and couldn't find such a usage.

– Steve
Mar 25 at 1:05




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55329786%2fspring-how-to-change-property%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript