Reputation: 157
I have troubles getting a javax.servlet.ServletConfig
into a class annotated with org.springframework.context.annotation.Configuration
.
My team decided that we should use spring for dependency injection and I'm trying to use it to migrate one of our simple Rest services.
My constraints are:
org.springframework:spring-context
from the spring project.web.xml
. I need to get it, instantiate a Bean with it and inject the resulting bean at several place in the code.What I already have:
The code use javax.ws.rs.core.Application
, with a class that look like that:
public class MyApplication extends Application {
@Context
private ServletConfig cfg;
public DSApplication() {
}
@Override
public Set<Class<?>> getClasses() {
return new HashSet<>();
}
@Override
public Set<Object> getSingletons() {
Set<Object> set = new HashSet<>();
String injectionStr = cfg.getInitParameter("injection");
boolean injection = false;
if (null != injectionStr && !injectionStr.isEmpty()) {
injection = Boolean.valueOf(injectionStr);
}
if (injection) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
DSServiceProducer.class,
CContextBeanProvider.class
);
IDSService service = context.getBean(IDSService.class);
set.add(service);
} else {
set.add(new DSService()); //Old way
}
return set;
}
}
I need the servlet config in CContextBeanProvider
, which look like:
@Configuration
public class CContextBeanProvider {
private ServletConfig cfg; // How to get this here ?
@Bean
public CContextBean cContextBean() {
String bean = cfg.getInitParameter("cpuContext");
return new CContextBean(bean);
}
}
CContextBean is a setting bean initialized from a string found in the web.xml of the service.
Upvotes: 0
Views: 557
Reputation: 76
Could you please try to add all jersey CDI related jars to your applications ?
Upvotes: 0