• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Nullpointer for Repo using springboot, hibernate and java FX

 
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm building a spring boot app and need to keep a timestamp containing when the program last runned. So I created a table for it. In the stopmethod of my main I try to save the timestamp to the db, but keep getting a nullpointerexeption, I think caused by the autowirerin failling. Anny tips?

My main:


The Stacktrace:

 
Rancher
Posts: 4801
50
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SpringApplication.run is supposed to be called in the main() method.
This allows Spring to then create everything it needs, including the autowiring.
At the moment your code is creating the Main instance itself, and then calling SpringApplication.run, so as you thought, the wiring is not being done for the already-existing Main instance.

I'm not too sure how you are supposed to launch them both exactly.
Might need some digging around for that.
 
Daniel Demesmaecker
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not so a pretty solution, but would it help if I maded it a static varriable in a different class?
 
Daniel Demesmaecker
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:Not so a pretty solution, but would it help if I maded it a static varriable in a different class?


and the maded a instance of that class?
 
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This looks like it has some useful tips.
 
Daniel Demesmaecker
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It dosn't, the problem is not fx related or how to combine everything. Everything is working great. The problem is how to autowire my repo from the mainClass.
If I try the same code in a different class, it works
I remember a spring mvc project I worked on a while a go and there I could do it this way:

but that dosn't work in this case.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:It dosn't, the problem is not fx related or how to combine everything. Everything is working great. The problem is how to autowire my repo from the mainClass.



But that is the problem.

You are trying to autowire the Main class while you are inside the instance of the Main class you want to autowire.


That call to SpringApplication.run cannot Autowire the TimeStampRepo instance that is inside the class that this method is a part of.
Indeed, that call will result in Spring creating another Main instance with the Autowired value, but that instance will not have kicked off as a JavaFX app.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic