Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

How to Excecute Logic Before SpringBoot Application Starts?

 
Bartender
Posts: 1752
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to just run some code in the Spring ApplicationClass before Spring starts up to make sure a TCP/IP server is running. If it's not running, the code will load it.

However, just putting that Java code in the Spring Application main() method does not work at all.

So, what is required to run some pre-application start code in SpringBoot?

(or is it recommended to just JAR up that separate server start logic and run it on computer restart?)

The sites I looked at online were not clear.

Thanks in advance,

- mike
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean with "does not work at all"? What exactly did you try and what problems exactly did you have with it? Any error messages?

You can execute whatever you want in the main() method before you call SpringApplication.run(), there's no special reason why this wouldn't work.
 
Mike London
Bartender
Posts: 1752
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jesper de Jong wrote:What do you mean with "does not work at all"? What exactly did you try and what problems exactly did you have with it? Any error messages?

You can execute whatever you want in the main() method before you call SpringApplication.run(), there's no special reason why this wouldn't work.



That is what I thought as well.

I have logging statements before and after the static method I'm calling (to start the TCP/IP server). But the logging isn't logging those strings and, similarly, the logging statements in the static method aren't being logged either.

How is that possible?

Thanks,

- mike
 
Rancher
Posts: 4576
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has the logging system started up at that point?
Isn't that one of the things Spring Boot loads up?
 
Mike London
Bartender
Posts: 1752
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:Has the logging system started up at that point?
Isn't that one of the things Spring Boot loads up?



Yeah, I thought of that too.

But, in any case, the TCP/IP server isn't getting started from the static call in main() so I guess I'll create a standalone executable JAR and auto-start that at the OS level. That approach may be better since as the application grows, they might not always want to start that TCP/IP server.

Thanks,

- mike
 
This tiny ad is guaranteed to be gluten free.
ScroogeXHTML 9.0 - RTF to HTML5 and XHTML converter
https://coderanch.com/t/731949/ScroogeXHTML-RTF-HTML-XHTML-converter
    Bookmark Topic Watch Topic
  • New Topic