Skip to content

Commit 9c7debe

Browse files
committed
Changes configuration from XML to Java for the cxf-spring module
1 parent c738c9e commit 9c7debe

9 files changed

Lines changed: 77 additions & 40 deletions

File tree

‎apache-cxf/cxf-spring/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target/

‎apache-cxf/cxf-spring/pom.xml‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<artifactId>maven-war-plugin</artifactId>
2020
<version>2.6</version>
2121
<configuration>
22-
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
22+
<failOnMissingWebXml>false</failOnMissingWebXml>
2323
</configuration>
2424
</plugin>
2525
<plugin>
@@ -110,8 +110,13 @@
110110
</dependency>
111111
<dependency>
112112
<groupId>org.springframework</groupId>
113-
<artifactId>spring-web</artifactId>
113+
<artifactId>spring-webmvc</artifactId>
114114
<version>${spring.version}</version>
115115
</dependency>
116+
<dependency>
117+
<groupId>javax.servlet</groupId>
118+
<artifactId>javax.servlet-api</artifactId>
119+
<version>3.1.0</version>
120+
</dependency>
116121
</dependencies>
117122
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.cxf.spring;
2+
3+
import javax.servlet.ServletContext;
4+
import javax.servlet.ServletRegistration;
5+
6+
import org.apache.cxf.transport.servlet.CXFServlet;
7+
import org.springframework.web.WebApplicationInitializer;
8+
import org.springframework.web.context.ContextLoaderListener;
9+
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
10+
11+
public class AppInitializer implements WebApplicationInitializer {
12+
@Override
13+
public void onStartup(ServletContext container) {
14+
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
15+
context.register(ServiceConfiguration.class);
16+
container.addListener(new ContextLoaderListener(context));
17+
18+
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new CXFServlet());
19+
dispatcher.addMapping("/services");
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.cxf.spring;
2+
3+
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
@Configuration
8+
public class ClientConfiguration {
9+
@Bean(name = "client")
10+
public Object generateProxy() {
11+
return proxyFactoryBean().create();
12+
}
13+
14+
@Bean
15+
public JaxWsProxyFactoryBean proxyFactoryBean() {
16+
JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
17+
proxyFactory.setServiceClass(Baeldung.class);
18+
proxyFactory.setAddress("http://localhost:8080/services/baeldung");
19+
return proxyFactory;
20+
}
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.cxf.spring;
2+
3+
import javax.xml.ws.Endpoint;
4+
5+
import org.apache.cxf.bus.spring.SpringBus;
6+
import org.apache.cxf.jaxws.EndpointImpl;
7+
import org.springframework.context.annotation.Bean;
8+
import org.springframework.context.annotation.Configuration;
9+
10+
@Configuration
11+
public class ServiceConfiguration {
12+
@Bean
13+
public SpringBus springBus() {
14+
return new SpringBus();
15+
}
16+
17+
@Bean
18+
public Endpoint endpoint() {
19+
EndpointImpl endpoint = new EndpointImpl(springBus(), new BaeldungImpl());
20+
endpoint.publish("http://localhost:8080/services/baeldung");
21+
return endpoint;
22+
}
23+
}

‎apache-cxf/cxf-spring/src/main/resources/client-beans.xml‎

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎apache-cxf/cxf-spring/src/main/webapp/WEB-INF/cxf-servlet.xml‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎apache-cxf/cxf-spring/src/main/webapp/WEB-INF/web.xml‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

‎apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/StudentTest.java‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
import static org.junit.Assert.assertEquals;
44

55
import org.junit.Test;
6-
import org.springframework.context.support.ClassPathXmlApplicationContext;
6+
import org.springframework.context.ApplicationContext;
7+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
78

89
public class StudentTest {
9-
private ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "client-beans.xml" });
10-
private Baeldung baeldungProxy;
11-
12-
{
13-
baeldungProxy = (Baeldung) context.getBean("client");
14-
}
10+
private ApplicationContext context = new AnnotationConfigApplicationContext(ClientConfiguration.class);
11+
private Baeldung baeldungProxy = (Baeldung) context.getBean("client");
1512

1613
@Test
1714
public void whenUsingHelloMethod_thenCorrect() {

0 commit comments

Comments
 (0)