diff --git a/apache-cxf/cxf-spring/.gitignore b/apache-cxf/cxf-spring/.gitignore
new file mode 100644
index 0000000000..2f7896d1d1
--- /dev/null
+++ b/apache-cxf/cxf-spring/.gitignore
@@ -0,0 +1 @@
+target/
diff --git a/apache-cxf/cxf-spring/pom.xml b/apache-cxf/cxf-spring/pom.xml
index 431c35c51d..aa72edb739 100644
--- a/apache-cxf/cxf-spring/pom.xml
+++ b/apache-cxf/cxf-spring/pom.xml
@@ -19,7 +19,7 @@
maven-war-plugin
2.6
- src/main/webapp/WEB-INF/web.xml
+ false
@@ -110,8 +110,13 @@
org.springframework
- spring-web
+ spring-webmvc
${spring.version}
+
+ javax.servlet
+ javax.servlet-api
+ 3.1.0
+
diff --git a/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/AppInitializer.java b/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/AppInitializer.java
new file mode 100644
index 0000000000..036bf66a52
--- /dev/null
+++ b/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/AppInitializer.java
@@ -0,0 +1,21 @@
+package com.baeldung.cxf.spring;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletRegistration;
+
+import org.apache.cxf.transport.servlet.CXFServlet;
+import org.springframework.web.WebApplicationInitializer;
+import org.springframework.web.context.ContextLoaderListener;
+import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
+
+public class AppInitializer implements WebApplicationInitializer {
+ @Override
+ public void onStartup(ServletContext container) {
+ AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
+ context.register(ServiceConfiguration.class);
+ container.addListener(new ContextLoaderListener(context));
+
+ ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new CXFServlet());
+ dispatcher.addMapping("/services");
+ }
+}
\ No newline at end of file
diff --git a/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ClientConfiguration.java b/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ClientConfiguration.java
new file mode 100644
index 0000000000..a2f124705b
--- /dev/null
+++ b/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ClientConfiguration.java
@@ -0,0 +1,21 @@
+package com.baeldung.cxf.spring;
+
+import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class ClientConfiguration {
+ @Bean(name = "client")
+ public Object generateProxy() {
+ return proxyFactoryBean().create();
+ }
+
+ @Bean
+ public JaxWsProxyFactoryBean proxyFactoryBean() {
+ JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
+ proxyFactory.setServiceClass(Baeldung.class);
+ proxyFactory.setAddress("http://localhost:8080/services/baeldung");
+ return proxyFactory;
+ }
+}
\ No newline at end of file
diff --git a/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ServiceConfiguration.java b/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ServiceConfiguration.java
new file mode 100644
index 0000000000..f1fac579ab
--- /dev/null
+++ b/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ServiceConfiguration.java
@@ -0,0 +1,24 @@
+package com.baeldung.cxf.spring;
+
+import javax.xml.ws.Endpoint;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.bus.spring.SpringBus;
+import org.apache.cxf.jaxws.EndpointImpl;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class ServiceConfiguration {
+ @Bean(name = Bus.DEFAULT_BUS_ID)
+ public SpringBus springBus() {
+ return new SpringBus();
+ }
+
+ @Bean
+ public Endpoint endpoint() {
+ EndpointImpl endpoint = new EndpointImpl(springBus(), new BaeldungImpl());
+ endpoint.publish("http://localhost:8080/services/baeldung");
+ return endpoint;
+ }
+}
\ No newline at end of file
diff --git a/apache-cxf/cxf-spring/src/main/resources/client-beans.xml b/apache-cxf/cxf-spring/src/main/resources/client-beans.xml
deleted file mode 100644
index 626252b565..0000000000
--- a/apache-cxf/cxf-spring/src/main/resources/client-beans.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/apache-cxf/cxf-spring/src/main/webapp/WEB-INF/cxf-servlet.xml b/apache-cxf/cxf-spring/src/main/webapp/WEB-INF/cxf-servlet.xml
deleted file mode 100644
index 9fe87ba9ee..0000000000
--- a/apache-cxf/cxf-spring/src/main/webapp/WEB-INF/cxf-servlet.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
diff --git a/apache-cxf/cxf-spring/src/main/webapp/WEB-INF/web.xml b/apache-cxf/cxf-spring/src/main/webapp/WEB-INF/web.xml
deleted file mode 100644
index 43a03b1d8b..0000000000
--- a/apache-cxf/cxf-spring/src/main/webapp/WEB-INF/web.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
- cxf
- org.apache.cxf.transport.servlet.CXFServlet
- 1
-
-
- cxf
- /services/*
-
-
diff --git a/apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/StudentTest.java b/apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/StudentTest.java
index 44a9d11687..794275b4d6 100644
--- a/apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/StudentTest.java
+++ b/apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/StudentTest.java
@@ -3,15 +3,12 @@ package com.baeldung.cxf.spring;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class StudentTest {
- private ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "client-beans.xml" });
- private Baeldung baeldungProxy;
-
- {
- baeldungProxy = (Baeldung) context.getBean("client");
- }
+ private ApplicationContext context = new AnnotationConfigApplicationContext(ClientConfiguration.class);
+ private Baeldung baeldungProxy = (Baeldung) context.getBean("client");
@Test
public void whenUsingHelloMethod_thenCorrect() {