Ich arbeite an einer Spring Boot-Anwendung, in der ich diese Anwendung verwenden, um einen SOAP-Webdienst verfügbar zu machen. Ich benutze Apache CFX Framework für SOAP impl in Spring Boot App. Ich verwende Annotation-basierten Ansatz.Nicht in der Lage, Anwendungskontext in Spring Start App zu laden
Ich habe Probleme beim Festlegen des Anwendungskontexts aus der Spring Boot-Konfigurationsdatei in einem der Beans. Unten ist mein Code.
@SpringBootApplication
@ComponentScan("com.test")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Die Konfigurationsdatei ist wie folgt.
@Configuration
public class WebServiceConfiguration {
//All individual bean definitions should go here
@Autowired
ApplicationContext appContext;
@Bean
public ServletRegistrationBean cxfServlet() {
return new ServletRegistrationBean(new CXFServlet(), "/soap-api/*");
}
@Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus() {
return new SpringBus();
}
@Bean(name="IValidator")
public IValidator getValidator(){
return new Validator();
}
@Bean(name="SOAPprocessImpl")
public IPSoap getService() {
return new SOAPprocessImpl();
}
@Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(springBus(), getService());
endpoint.publish("/WS_1.0");
endpoint.setWsdlLocation("process.wsdl");
return endpoint;
}
Jetzt habe ich die Bohne SOAPprocessImpl Implementierung, bei der ich brauche den Anwendungskontext zu bekommen, so dass ich in der Validator Bohne handhaben zu bekommen. Ich habe SOAPprocessImpl als Bean in der Konfigurationsdatei deklariert. Der Code ist wie unten
@javax.jws.WebService (endpointInterface="com.test.IPSoap")
public class SOAPprocessImpl implements IPSoap, ApplicationContextAware {
private static ApplicationContext context;
public static ApplicationContext getApplicationContext() {
return context;
}
@Override
public void setApplicationContext(ApplicationContext ac)
throws BeansException {
context = ac;
}
private static final Logger logger = Logger.getLogger(SOAPprocessImpl.class.getName());
private IValidator validator = (IValidator) context.getBean("IValidator"); // context is NULL here
public IRResponse GetBalance(TSSearchParams SearchParams) {
// Some processing logic
}
}
Also das Problem ist, dass, wenn ich ausführen, um die Boot-Anwendung, indem auf den eingebetteten Tomcat bereitstellen dann der Anwendungskontext ist nicht einmal in der SOAPprocessImpl Klasse festgelegt zu werden, nachdem die Umsetzung ApplicationContextAware. Ich habe auch Autowiring versucht, aber das funktioniert auch nicht.
Seltsamerweise habe ich versucht zu sehen, ob ich den ApplicationContext in der Konfigurationsdatei erhalten kann, wo alle Bean definiert sind. Hier wird es richtig eingestellt.
Kann mir jemand helfen, dieses Problem zu lösen. Ich bin neu bei Spring Boot und habe vielleicht einige Konfigurationen verpasst. Danke im Voraus.
Danke. Ich habe versucht, aber es funktioniert immer noch nicht. Der Kontext ist immer noch null. – vikeng21
Welches Paket 'SOAPprocessImpl' befindet sich? – developer
SOAPprocessImpl befindet sich in einem anderen Paket. com.test.config und WebServiceConfiguration befinden sich in einem anderen Paket. com.test.ws – vikeng21