I am working on migrating a j2EE application to spring-boot.. I face here lot of challenges.. need your small help , The below are the steps I followed
- Did the setup of POM, JAR and WAR packing
- Tried tie convert the Servlet to RestController
- Filters I have registered as
@Configuration
public class FilterConfigService {
@Bean
public FilterRegistrationBean mdcFilter() {
FilterRegistrationBean filterRegBean = new FilterRegistrationBean();
filterRegBean.setFilter(new MDCFilter());
filterRegBean.addUrlPatterns("/v2/*");
filterRegBean.setOrder(1);
return filterRegBean;
}
@Bean
public FilterRegistrationBean apiOriginFilter() {
FilterRegistrationBean filterRegBean = new FilterRegistrationBean();
filterRegBean.setFilter(new ApiOriginFilter());
filterRegBean.addUrlPatterns("/v2/*");
filterRegBean.setOrder(2);
return filterRegBean;
}
}
- There was singleton class for instantiating some necessary stuffs through Init() of servlet which I removed as all the beans are by default singleton in scope and did as below to instantiate (Dont know if this is the good practice)
@Configuration
public class PdfExtractServerConfig implements ApplicationListener<ContextRefreshedEvent> {
@Autowired
PdfExtractServer pdfExtractServer;
private static Logger log = Logger.getLogger(PdfExtractServerConfig.class);
@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
try {
pdfExtractServer.instance(); // this was called in init of servlet
System.out.println("instance created ..");
}
catch (Throwable e) {
log.error("Unable to start PdfExtractServer", e);
throw e;
}
//Start monitoring for system health
ResourceCheck.startMonitoring();
SplunkMgr.instance().addSplunkMessage("BackPressure", LogLevel.INFO);
}
}
The single ton class is like as below..
Before it was like
public static PdfExtractServer instance() {
if (instance == null) {
synchronized (startupLock) {
if (instance == null) {
instance = new PdfExtractServer();
instance.start("PES");
}
}
}
return instance;
}
now I made this as
public static PdfExtractServer instance() {
// instance = new PdfExtractServer();
instance.start("PES");
return instance;
}
This is my test controller
@RestController
//@RequestMapping("/")
public class Test {
@RequestMapping("/test" )
public String test(){
return "Tested OK";
}
}
I don't understand where do I do wrong .. when I try to run this renders
Unable to start PdfExtractServer java.lang.NullPointerException at com.it.pes.pdfextract.service.PdfExtractServer.instance(PdfExtractServer.java:78) at com.it.pes.pdfextract.config.PdfExtractServerConfig.onApplicationEvent(PdfExtractServerConfig.java:24) at com.it.pes.pdfextract.config.PdfExtractServerConfig.onApplicationEvent(PdfExtractServerConfig.java:13) at com.it.pes.pdfextract.config.PdfExtractServerConfig$$EnhancerBySpringCGLIB$$e703305a.onApplicationEvent() at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347) at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:883) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
Observation: I tried to register my filters through glassfish jersey, but internallly in some jars , javax.ws.rs-api of 1.1.1 is used so there was conflict and my app was not up, hence to registe the Filters in different way as mentioned above.
Your help would be really great move for me.. thanks in advance..