I have a Spring 4 application which I deploy as a WAR. Now I have a requirement where I cannot deploy the WAR, and instead use a single class to invoke the functionalities of the Spring application.
package com.company.project.services;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import com.company.project.bo.service.CleanupServiceBo;
import com.company.project.bo.service.BackupServiceBo;
import com.company.project.bo.service.HousekeepingServiceBo;
@Component
public class MyStandaloneComponent {
@Autowired
private CleanupServiceBo cleanupServiceBo;
@Autowired
private BackupServiceBo backupServiceBo;
@Autowired
private HousekeepingServiceBo housekeepingServiceBo;
public static void main(String[] args) {
try {
cleanupServiceBo.deleteOldAuditRecords();
backupServiceBo.backup();
housekeepingServiceBo.doHousekeeping();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Now each of the three Autowired services have more Autowired components and services in them. And each of the three Autowired services interact with Database using JPA. I have an applicationContext.xml file describing various beans and JPA database connectivity.
Is it possible to create the application context of the spring application and use it? In that case, which application context to use such as AnnotationConfigApplicationContext, ClassPathXmlApplicationContext, AnnotationConfigApplicationContext etc.?
What would I need to run the above standalone class with Autowired services, without deploying the WAR?