나는 모든 질문을 이해할 수 있을지 확신하지 못합니다. +500 현상금은 너무 쉽게 보입니다. 원하는 코드가 아닌 경우 일부 코드를 게시하십시오. 어쨌든
, 의존성 주입과 웹 서비스를 생성하는 간단한 솔루션 : 클래스 패스 스캐닝 (Reflections)와보다 정교한 솔루션 아래
final Module module = new HelloModule();
final Injector injector = Guice.createInjector(module);
final HelloService helloService = injector.getInstance(HelloService.class);
Endpoint.publish("http://localhost:8080/helloService", helloService);
JAX-WS Guice integration에서 마커스 에릭손의 코드를 기반으로. 이라는 주석이 달린 모든 클래스를 웹 서비스로 게시합니다 (Endpoint.publish()
).
private void initGuicedWebservices(final String packageNamePrefix)
throws Exception {
final Reflections reflections = new Reflections(packageNamePrefix);
final Set<Class<?>> guiceManaged =
reflections.getTypesAnnotatedWith(GuiceManaged.class);
for (final Class<?> clazz : guiceManaged) {
doGuice(clazz);
}
}
private void doGuice(final Class<?> clazz) throws Exception {
final GuiceManaged guiceManagedAnnotation =
clazz.getAnnotation(GuiceManaged.class);
final Injector injector = createInjector(guiceManagedAnnotation);
final Object serviceObject = clazz.newInstance();
injector.injectMembers(serviceObject);
final String address = guiceManagedAnnotation.address();
Endpoint.publish(address, serviceObject);
}
private Injector createInjector(final GuiceManaged guiceManagedAnnotation)
throws Exception {
final Class<? extends Module>[] moduleClasses =
guiceManagedAnnotation.module();
final List<Module> moduleInstances = new ArrayList<Module>();
for (final Class<? extends Module> moduleClass : moduleClasses) {
moduleInstances.add(moduleClass.newInstance());
}
return Guice.createInjector(moduleInstances);
}
GuiceManaged
주석 :
@Retention(RUNTIME)
@Target(TYPE)
@Documented
public @interface GuiceManaged {
public Class<? extends Module>[] module();
public String address();
}
그리고 HelloServiceImpl
조각 :
@GuiceManaged(module = HelloModule.class,
address = "http://localhost:8080/helloService")
@WebService
public class HelloServiceImpl implements HelloService {
@Inject // bound in HelloModule
public GreetingsService greetingsService;
@Override
@WebMethod
public String sayHello(final String name) {
return greetingsService.sayHello(name);
}
}
그것은 내가 할로 구현 객체에 공급자를 주입하여 내가 지금에 의해 얻을 수 있습니다 밝혀졌다 깊게 중첩 된 주입이 필요하지 않습니다. 바운티가이 사실을 깨닫게 해주는 대답을주었습니다. –