I use class with @ configuration annotation to configure my spring application:
@configeration public class spring configuration {@Value ("$ {driver}") string driver; @ Value ("$ {url}") string URL; @well ("$ {minIdle}") Private Ent Minedal; // snip. @ Bean (delete method = "off") Public data source data source () {data source data source = new data source (); DataSource.setDriverClassName (driver); DataSource.setUrl (URL); DataSource.setUsername (user); DataSource.setPassword (password); DataSource.setMinIdle (minIdle); Return data source; }
and property files CLASSPATH
driver = org.postgresql.Driver url = jdbc: postgresql: servicerepodb minIdle = 1
I would like to receive your datasource Object is configured in the DAO class:
ApplicationContext ctx = new antitension config applications contaxes (spring configuration class); Datasource datasource = CTXGetbin (datasource class);
But I get an error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring configuration': injection of autowired dependencies fail; Nested exception org.springframework.beans.factory.BeanCreationException: could not autowire field: private int de.hska.repo.configuration.SpringConfiguration.minIdle; Nested exception org.springframework.beans.TypeMismatchException: failed to change the value of the required type 'int' type 'java.lang.String'; Nested exception ** java.lang.NumberFormatException: for input string: "$ {minIdle}" ** by reason: java.lang.NumberFormatException: for input string: ** "$ {minIdle}" ** java.lang On (unknown source) java.lang.Integer.valueOf (unknown source) at .navaFormatException.forInputString (** Unknown source **) at java.lang.Integer.parseIntThis string properties (driver's Worked with), Url), but $ {minIdle} (type int's) can not be resolved! Please help. Thanx in advance!
& lt; Reference: Asset-Placeholder / & gt;
belongs to the element. Your error message is your belief that the root cause of the problem is:
Reason: java.lang.NumberFormatException: for input string: "$ {minIdle}"
I believe the problem is that property locator configurator
has not been initiated if you want it to be & lt; Reference: Asset-Placeholder / & gt;
element, all placeholders will be replaced with values related to a property file in a post process operation at the end of the priority process and
minIdle = demo string < / P>
If this was a parse error, and the attribute file contains such a row:
code>
would be used instead of "$ {minIdle}"After that, the error message < Code> "demo string"
When it comes to parsing, Spring will handle parsing your computer with
@Value
annotation and yourminIdle
field works fine on my computer :@ value ("$ {minIdle}") Private In Min Idle;
The only way to get your exception message is if I
& lt; Context: property-placeholder / & gt; Forgot to add the element
then I got the same exception message with the last property reached in the error message.Demo app
A small experiment that emits your problem:
@Value ("$ {A} ") Private string A; @ Value ("$ {b}") private integer; @bean public string demo () {System.out.println ("a:" + a); System.out.println ("B:" + B); One + "," + b; }
without
property-placeholder
element:Reason by: java.lang.NumberFormatException: for input string: " It works as expected with $ {B} "
property-placeholder
.
Comments
Post a Comment