• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Get DataSource Reference

 
Bartender
Posts: 1938
17
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I defined my datasource in application.properties.

Spring read the datasource properties, but in my main method in the Application class or even in a @RestMethod in that class, how do I access the DataSource reference so I can do some data access logic?

Spent a couple hours researching. Tried @Autowired and others like getJdbcTemplate() (which didn't compile)  that did not work.

Thanks in advance,

- mike
 
Mike London
Bartender
Posts: 1938
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it working!

Just needed:


.
.
to wire in the jdbc template.

This template saves lots of tedious JDBC boilerplate code.

- mike
reply
    Bookmark Topic Watch Topic
  • New Topic