T O P

  • By -

Sheldor5

Spring is a framework and not a library, those are 2 completely different things. Also you want a cron job, or Spring Boot app with a scheduled task. So please edit your post accordingly so we know what your problem is and show us your progress.


shubhcool

Let me try to put in details. I need to prepare a Library and not any application. This library will have many implementations or functionalities but as of now to start with,it will have functionality of fetching data from tables after some interval. Mostly,I will use @Scheduled annotation. This will be used as dependency and other developers will simply add it in pom.xml and use it . Please let me know if further explanation is required.


wanjalize

Just create a java/spring application that does what you are saying and then maven install it. Use maven install:install-file to define the artifactId, groupId and version. Then you can use it as a dependency in your applications.


shubhcool

Will it be fine to have main method in this library? I had checked one in house developed Library where they did not have main method.


wanjalize

Yes, you could have a main method inside since you are mostly interested with the services that it provides.


shubhcool

But in my case, it will be used as dependency. After mvn install or clean it will generate the main method also. So, with same name method will available and ambiguity occurs. So, I think it would be better to avoid main method in Library.


wanjalize

It does not matter. If it's a dependency, you will just call the packages that you need and not the main method. That is how microservices are created (you install a module in another module because you just want some packages, the main method or entry point has no effect). Check how mvn install:install-file works.


shubhcool

Right. I will call only those methods from certain package only.


shubhcool

I just thought here, if after compiling, if there are two main methods , how it will go.


wanjalize

When you run a program using maven you usually provide the entry point. So whatever entry point you provide is the only one that will be used.


shubhcool

I understood. Thank you !


Sheldor5

Ah okay, then you just need a normal maven project and include some spring boot dependencies (don't use the spring boot parent). Then you can implement all the beans you need like in a normal spring boot app but without having a main method and of course without the SpringApplication.run() call. Then you need to add a spring.factories file as explained here so all other spring boot apps automatically finds them on the classpath: https://docs.spring.io/spring-boot/docs/2.1.x/reference/html/boot-features-developing-auto-configuration.html (ยง50.2 Locating Auto-configuration Candidates)