• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to set Integer value from property file to Spring configuration <property> tag

 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Can anybody help me out how could I get the integer value from property file and set in the spring configuration xml file .

I have one property file and the values on this property file are:

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/myDb
jdbc.username=root
jdbc.password=password
jdbc.maxActive=50
jdbc.defaultAutoCommit=true


When I'm trying to get the jdbc.maxActive=50 value in my property file the application throwing exception .

In my xml file I am taking the value like this :

<property name="maxActive" value="#{new Integer('${jdbc.maxActive}')}" />



Thanks in advance ,
Sb



 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I doubt if this is getting resolved to the String '50' as mentioned in the configuration - '${jdbc.maxActive}'

In any case I would do this parsing to Integer in the setter method of my bean.
 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mohamed Sanaulla wrote:I doubt if this is getting resolved to the String '50' as mentioned in the configuration - '${jdbc.maxActive}'

In any case I would do this parsing to Integer in the setter method of my bean.



Mohamed , can you explain this a little more.

Sb
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need no parsing. Spring will parse for you. Just do this

 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jayesh,
I have already tried that you are suggesting and am getting :



I like to add one strange thing here ,while am adding the auto commit property of type Boolean like this


Application is working with no compilation / runtime error .

I have tried by using the parseInt property of Integer in the spring El



Here am getting the exception :



Satya
 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jayesh,
You are correct .I was getting the wrong property file and spring was throwing that exception.
Problem solved !!!.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic