From 44d15e5f748b1d36bc910d69e940c7f99b819ae3 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Tue, 18 Feb 2014 10:51:37 +0100 Subject: [PATCH] Changed XML app context to @Configuration --- .../ws/samples/weather/WeatherClient.java | 7 ++- .../samples/weather/WeatherConfiguration.java | 43 +++++++++++++++++++ weather/src/main/resources/log4j.properties | 2 - .../ws/samples/weather/applicationContext.xml | 16 ------- 4 files changed, 46 insertions(+), 22 deletions(-) create mode 100644 weather/src/main/java/org/springframework/ws/samples/weather/WeatherConfiguration.java delete mode 100644 weather/src/main/resources/org/springframework/ws/samples/weather/applicationContext.xml diff --git a/weather/src/main/java/org/springframework/ws/samples/weather/WeatherClient.java b/weather/src/main/java/org/springframework/ws/samples/weather/WeatherClient.java index f4ccc19..dcafafc 100644 --- a/weather/src/main/java/org/springframework/ws/samples/weather/WeatherClient.java +++ b/weather/src/main/java/org/springframework/ws/samples/weather/WeatherClient.java @@ -19,7 +19,7 @@ package org.springframework.ws.samples.weather; import java.text.SimpleDateFormat; import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.ws.client.core.support.WebServiceGatewaySupport; import org.springframework.ws.soap.client.core.SoapActionCallback; @@ -69,9 +69,8 @@ public class WeatherClient extends WebServiceGatewaySupport { public static void main(String[] args) { ApplicationContext context = - new ClassPathXmlApplicationContext("applicationContext.xml", - WeatherClient.class); - WeatherClient client = context.getBean("weatherClient", WeatherClient.class); + new AnnotationConfigApplicationContext(WeatherConfiguration.class); + WeatherClient client = context.getBean(WeatherClient.class); String zipCode = "94304"; if (args.length > 0) { diff --git a/weather/src/main/java/org/springframework/ws/samples/weather/WeatherConfiguration.java b/weather/src/main/java/org/springframework/ws/samples/weather/WeatherConfiguration.java new file mode 100644 index 0000000..2453adf --- /dev/null +++ b/weather/src/main/java/org/springframework/ws/samples/weather/WeatherConfiguration.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.ws.samples.weather; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.oxm.jaxb.Jaxb2Marshaller; + +@Configuration +public class WeatherConfiguration { + + @Bean + public Jaxb2Marshaller marshaller() { + Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); + marshaller.setContextPath("org.springframework.ws.samples.weather"); + return marshaller; + } + + @Bean + public WeatherClient weatherClient() { + WeatherClient client = new WeatherClient(); + client.setDefaultUri("http://wsf.cdyne.com/WeatherWS/Weather.asmx"); + Jaxb2Marshaller marshaller = marshaller(); + client.setMarshaller(marshaller); + client.setUnmarshaller(marshaller); + return client; + } + +} diff --git a/weather/src/main/resources/log4j.properties b/weather/src/main/resources/log4j.properties index 0f73a75..f50b419 100644 --- a/weather/src/main/resources/log4j.properties +++ b/weather/src/main/resources/log4j.properties @@ -1,6 +1,4 @@ log4j.rootLogger=WARN, stdout -log4j.logger.org.springframework.ws=DEBUG -log4j.logger.org.springframework.xml=DEBUG log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout diff --git a/weather/src/main/resources/org/springframework/ws/samples/weather/applicationContext.xml b/weather/src/main/resources/org/springframework/ws/samples/weather/applicationContext.xml deleted file mode 100644 index b733295..0000000 --- a/weather/src/main/resources/org/springframework/ws/samples/weather/applicationContext.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - -