diff --git a/pom.xml b/pom.xml
index a1fd6e3e8..55f4c1caf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -168,7 +168,6 @@
org.apache.tomcat
tomcat-jdbc
${tomcat-jdbc.version}
- runtime
diff --git a/readme.md b/readme.md
index 8f9cb72d1..fe8ee53f7 100644
--- a/readme.md
+++ b/readme.md
@@ -52,16 +52,16 @@ File -> Import -> Maven -> Existing Maven project
Spring MVC- Atom integration |
VetsAtomView.java
- mvc-view-config.xml
+ MvcViewConfig.java
|
Spring MVC - XML integration |
- mvc-view-config.xml |
+ MvcViewConfig.java |
Spring MVC - ContentNegotiatingViewResolver |
- mvc-view-config.xml |
+ MvcViewConfig.java |
Spring MVC Test Framework |
@@ -77,7 +77,7 @@ File -> Import -> Maven -> Existing Maven project
webjars |
webjars declaration inside pom.xml
- Resource mapping in Spring configuration
+ Resource mapping in Spring configuration
sample usage in JSP |
@@ -109,21 +109,21 @@ File -> Import -> Maven -> Existing Maven project
Transactions |
- business-config.xml
+ BusinessConfig.java
ClinicServiceImpl.java
|
Cache |
- tools-config.xml
+ ToolsConfig.java
ClinicServiceImpl.java
|
Bean Profiles |
- business-config.xml
+ JdbcConfig.java
ClinicServiceJdbcTests.java
web.xml
|
@@ -131,19 +131,21 @@ File -> Import -> Maven -> Existing Maven project
JdbcTemplate |
- business-config.xml
+ JdbcConfig.java
jdbc folder |
JPA |
- business-config.xml
+ SharedJpaConfig.java
+ JpaConfig.java
jpa folder |
Spring Data JPA |
- business-config.xml
+ SharedJpaConfig.java
+ SpringDataJpaConfig.java
springdatajpa folder |
diff --git a/src/main/java/org/springframework/samples/petclinic/config/BusinessConfig.java b/src/main/java/org/springframework/samples/petclinic/config/BusinessConfig.java
new file mode 100644
index 000000000..e41c16597
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/config/BusinessConfig.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2002-2013 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.
+ */
+/*
+ * Copyright 2002-2013 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.samples.petclinic.config;
+
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.context.annotation.ImportResource;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+@Configuration
+@ComponentScan("org.springframework.samples.petclinic.service")
+// Configurer that replaces ${...} placeholders with values from a properties file
+// (in this case, JDBC-related settings for the JPA EntityManager definition below)
+@PropertySource("classpath:spring/data-access.properties")
+@EnableTransactionManagement
+@Import({DataSourceConfig.class, InitDataSourceConfig.class, JdbcConfig.class, SharedJpaConfig.class, JpaConfig.class, SpringDataJpaConfig.class})
+public class BusinessConfig {
+
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/config/DataSourceConfig.java b/src/main/java/org/springframework/samples/petclinic/config/DataSourceConfig.java
new file mode 100644
index 000000000..d974bbb1c
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/config/DataSourceConfig.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2002-2013 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.
+ */
+/*
+ * Copyright 2002-2013 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.samples.petclinic.config;
+
+import javax.sql.DataSource;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Description;
+import org.springframework.context.annotation.Profile;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.core.env.Environment;
+import org.springframework.jndi.JndiObjectFactoryBean;
+
+@Configuration
+@PropertySource("classpath:spring/data-access.properties")
+public class DataSourceConfig {
+
+ @Autowired
+ private Environment env;
+
+ @Bean(name = "dataSource")
+ @Description("DataSource configuration for the tomcat jdbc connection pool")
+ @NotProfile("javaee")
+ public DataSource dataSource() {
+ // See here for more details on commons-dbcp versus tomcat-jdbc:
+ // http://blog.ippon.fr/2013/03/13/improving-the-performance-of-the-spring-petclinic-sample-application-part-3-of-5/-->
+ org.apache.tomcat.jdbc.pool.DataSource dataSource = new org.apache.tomcat.jdbc.pool.DataSource();
+ dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName"));
+ dataSource.setUrl(env.getProperty("jdbc.url"));
+ dataSource.setUsername(env.getProperty("jdbc.username"));
+ dataSource.setPassword(env.getProperty("jdbc.password"));
+ return dataSource;
+ }
+
+ @Bean(name = "dataSource")
+ @Description("JNDI DataSource for JEE environments")
+ @Profile("javaee")
+ public JndiObjectFactoryBean jndiDataSource()
+ throws IllegalArgumentException {
+ JndiObjectFactoryBean dataSource = new JndiObjectFactoryBean();
+ dataSource.setExpectedType(DataSource.class);
+ dataSource.setJndiName(env.getProperty("java:comp/env/jdbc/petclinic"));
+ return dataSource;
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/config/InitDataSourceConfig.java b/src/main/java/org/springframework/samples/petclinic/config/InitDataSourceConfig.java
new file mode 100644
index 000000000..211a8c06d
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/config/InitDataSourceConfig.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2002-2013 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.
+ */
+/*
+ * Copyright 2002-2013 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.samples.petclinic.config;
+
+import javax.annotation.PostConstruct;
+import javax.sql.DataSource;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
+import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
+
+@Configuration
+public class InitDataSourceConfig {
+
+ @Autowired
+ private Environment env;
+
+ @Autowired
+ private DataSource dataSource;
+
+ @PostConstruct
+ public void init() {
+ ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
+ databasePopulator.addScript(new ClassPathResource(env.getProperty("jdbc.initLocation")));
+ databasePopulator.addScript(new ClassPathResource(env.getProperty("jdbc.dataLocation")));
+ DatabasePopulatorUtils.execute(databasePopulator, dataSource);
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/config/JdbcConfig.java b/src/main/java/org/springframework/samples/petclinic/config/JdbcConfig.java
new file mode 100644
index 000000000..2b28cc973
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/config/JdbcConfig.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2002-2013 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.
+ */
+/*
+ * Copyright 2002-2013 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.samples.petclinic.config;
+
+import javax.sql.DataSource;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+
+@Configuration
+@Profile("jdbc")
+@ComponentScan("org.springframework.samples.petclinic.repository.jdbc")
+public class JdbcConfig {
+
+ @Autowired
+ private DataSource dataSource;
+
+
+ @Bean
+ public DataSourceTransactionManager dataSourceTransactionManager() {
+ return new DataSourceTransactionManager(dataSource);
+ }
+
+ @Bean(name="transactionManager")
+ public JdbcTemplate jdbcTemplate() {
+ return new JdbcTemplate(dataSource);
+ }
+
+ @Bean
+
+ public NamedParameterJdbcTemplate namedParameterJdbcTemplate() {
+ return new NamedParameterJdbcTemplate(dataSource);
+ }
+
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/config/JpaConfig.java b/src/main/java/org/springframework/samples/petclinic/config/JpaConfig.java
new file mode 100644
index 000000000..f447ae5b2
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/config/JpaConfig.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2002-2013 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.
+ */
+/*
+ * Copyright 2002-2013 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.samples.petclinic.config;
+
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
+
+@Configuration
+@Profile("jpa")
+@ComponentScan("org.springframework.samples.petclinic.repository.jpa")
+public class JpaConfig {
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/config/MvcCoreConfig.java b/src/main/java/org/springframework/samples/petclinic/config/MvcCoreConfig.java
new file mode 100644
index 000000000..e96af0043
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/config/MvcCoreConfig.java
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2002-2013 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.
+ */
+/*
+ * Copyright 2002-2013 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.samples.petclinic.config;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Description;
+import org.springframework.context.annotation.Import;
+import org.springframework.context.support.ReloadableResourceBundleMessageSource;
+import org.springframework.format.FormatterRegistry;
+import org.springframework.http.MediaType;
+import org.springframework.samples.petclinic.service.ClinicService;
+import org.springframework.samples.petclinic.web.PetTypeFormatter;
+import org.springframework.web.servlet.HandlerExceptionResolver;
+import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
+import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;
+
+/**
+ *
+ * The ContentNegotiatingViewResolver delegates to the
+ * InternalResourceViewResolver and BeanNameViewResolver, and uses the requested
+ * media type (determined by the path extension) to pick a matching view. When
+ * the media type is 'text/html', it will delegate to the
+ * InternalResourceViewResolver's JstlView, otherwise to the
+ * BeanNameViewResolver.
+ *
+ */
+@Configuration
+@EnableWebMvc
+@Import(MvcViewConfig.class)
+// POJOs labeled with the @Controller and @Service annotations are
+// auto-detected.
+@ComponentScan(basePackages = { "org.springframework.samples.petclinic.web" })
+public class MvcCoreConfig extends WebMvcConfigurerAdapter {
+
+ @Autowired
+ private ClinicService clinicService;
+
+ @Override
+ public void configureContentNegotiation(
+ ContentNegotiationConfigurer configurer) {
+ configurer.ignoreAcceptHeader(true);
+ configurer.defaultContentType(MediaType.TEXT_HTML);
+ configurer.mediaType("html", MediaType.TEXT_HTML);
+ configurer.mediaType("xml", MediaType.APPLICATION_XML);
+ configurer.mediaType("atom", MediaType.APPLICATION_ATOM_XML);
+ }
+
+ @Override
+ public void configureDefaultServletHandling(
+ DefaultServletHandlerConfigurer configurer) {
+ // Serve static resources (*.html, ...) from src/main/webapp/
+ configurer.enable();
+ }
+
+ @Override
+ public void addFormatters(FormatterRegistry formatterRegistry) {
+ formatterRegistry.addFormatter(petTypeFormatter());
+ }
+
+ @Bean
+ public PetTypeFormatter petTypeFormatter() {
+ return new PetTypeFormatter(clinicService);
+ }
+
+ @Override
+ public void addResourceHandlers(ResourceHandlerRegistry registry) {
+ // all resources inside folder src/main/webapp/resources are mapped so
+ // they can be refered to inside JSP files (see header.jsp for more
+ // details)
+ registry.addResourceHandler("/resources/**").addResourceLocations(
+ "/resources/");
+ // uses WebJars so Javascript and CSS libs can be declared as Maven dependencies (Bootstrap, jQuery...)
+ registry.addResourceHandler("/webjars/**").addResourceLocations(
+ "classpath:/META-INF/resources/webjars/");
+ }
+
+ @Override
+ public void addViewControllers(ViewControllerRegistry registry) {
+ registry.addViewController("/").setViewName("welcome");
+ }
+
+ @Bean(name = "messageSource")
+ @Description("Message source for this context, loaded from localized 'messages_xx' files.")
+ public ReloadableResourceBundleMessageSource reloadableResourceBundleMessageSource() {
+ // Files are stored inside src/main/resources
+ ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
+ messageSource.setBasenames("classpath:messages/messages");
+ return messageSource;
+ }
+
+ /**
+ * Resolves specific types of exceptions to corresponding logical view names
+ * for error views.
+ *
+ *
+ * View name resolved using bean of type InternalResourceViewResolver
+ * (declared in {@link MvcViewConfig}).
+ */
+ @Override
+ public void configureHandlerExceptionResolvers(
+ List exceptionResolvers) {
+ SimpleMappingExceptionResolver exceptionResolver = new SimpleMappingExceptionResolver();
+ // results into 'WEB-INF/jsp/exception.jsp'
+ exceptionResolver.setDefaultErrorView("exception");
+ // needed otherwise exceptions won't be logged anywhere
+ exceptionResolver.setWarnLogCategory("warn");
+ exceptionResolvers.add(exceptionResolver);
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/config/MvcViewConfig.java b/src/main/java/org/springframework/samples/petclinic/config/MvcViewConfig.java
new file mode 100644
index 000000000..3b16448c5
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/config/MvcViewConfig.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2002-2013 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.
+ */
+/*
+ * Copyright 2002-2013 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.samples.petclinic.config;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Description;
+import org.springframework.oxm.Marshaller;
+import org.springframework.oxm.jaxb.Jaxb2Marshaller;
+import org.springframework.samples.petclinic.model.Vets;
+import org.springframework.samples.petclinic.web.VetsAtomView;
+import org.springframework.web.accept.ContentNegotiationManager;
+import org.springframework.web.servlet.ViewResolver;
+import org.springframework.web.servlet.view.BeanNameViewResolver;
+import org.springframework.web.servlet.view.ContentNegotiatingViewResolver;
+import org.springframework.web.servlet.view.InternalResourceViewResolver;
+import org.springframework.web.servlet.view.JstlView;
+import org.springframework.web.servlet.view.xml.MarshallingView;
+
+@Configuration
+public class MvcViewConfig {
+
+ @Bean
+ public ContentNegotiatingViewResolver contentNegotiatingViewResolver(ContentNegotiationManager manager) {
+ ContentNegotiatingViewResolver contentNegotiatingViewResolver = new ContentNegotiatingViewResolver();
+ List viewResolvers = new ArrayList();
+ viewResolvers.add(internalResourceViewResolver());
+ viewResolvers.add(beanNameViewResolver());
+ contentNegotiatingViewResolver.setViewResolvers(viewResolvers );
+ contentNegotiatingViewResolver.setContentNegotiationManager(manager);
+ return contentNegotiatingViewResolver;
+ }
+
+ @Bean
+ @Description("Default viewClass: JSTL view (JSP with html output)")
+ public ViewResolver internalResourceViewResolver() {
+ // Example: a logical view name of 'vets' is mapped to
+ // '/WEB-INF/jsp/vets.jsp'
+ InternalResourceViewResolver bean = new InternalResourceViewResolver();
+ bean.setViewClass(JstlView.class);
+ bean.setPrefix("/WEB-INF/jsp/");
+ bean.setSuffix(".jsp");
+ return bean;
+ }
+
+ @Bean
+ @Description("Used for 'xml' and 'atom' views")
+ public ViewResolver beanNameViewResolver() {
+ return new BeanNameViewResolver();
+ }
+
+ @Bean(name = "vets/vetList.atom")
+ @Description("Renders an Atom feed of the visits. Used by the BeanNameViewResolver")
+ public VetsAtomView vetsAtomView() {
+ return new VetsAtomView();
+ }
+
+ @Bean(name = "vets/vetList.xml")
+ @Description("Renders an XML view. Used by the BeanNameViewResolver")
+ public MarshallingView marshallingView() {
+ return new MarshallingView(marshaller());
+ }
+
+ @Bean
+ @Description("Object-XML mapping declared using annotations inside 'Vets'")
+ public Marshaller marshaller() {
+ Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
+ marshaller.setClassesToBeBound(Vets.class);
+ return marshaller;
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/config/NotProfile.java b/src/main/java/org/springframework/samples/petclinic/config/NotProfile.java
new file mode 100644
index 000000000..a63a40824
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/config/NotProfile.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2002-2013 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.
+ */
+/*
+ * Copyright 2002-2013 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.samples.petclinic.config;
+
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.springframework.context.annotation.Conditional;
+
+
+/**
+ * Indicates that a component is eligible for registration when none of the {@linkplain
+ * #value specified profiles} is active.
+*/
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.TYPE, ElementType.METHOD})
+@Documented
+@Conditional(NotProfileCondition.class)
+public @interface NotProfile {
+
+ /**
+ * The set of profiles for which the annotated component should not be registered.
+ */
+ String[] value();
+
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/config/NotProfileCondition.java b/src/main/java/org/springframework/samples/petclinic/config/NotProfileCondition.java
new file mode 100644
index 000000000..b45376112
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/config/NotProfileCondition.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2002-2013 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.
+ */
+/*
+ * Copyright 2002-2013 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.samples.petclinic.config;
+
+import org.springframework.context.annotation.Condition;
+import org.springframework.context.annotation.ConditionContext;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+import org.springframework.util.MultiValueMap;
+
+/**
+ * {@link Condition} that matches based on the value of a {@link NotProfile @NotProfile}
+ * annotation.
+ *
+ */
+class NotProfileCondition implements Condition {
+
+ @Override
+ public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
+ if (context.getEnvironment() != null) {
+ MultiValueMap attrs = metadata.getAllAnnotationAttributes(NotProfile.class.getName());
+ if (attrs != null) {
+ for (Object value : attrs.get("value")) {
+ if (context.getEnvironment().acceptsProfiles(((String[]) value))) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+ return true;
+ }
+
+}
+
diff --git a/src/main/java/org/springframework/samples/petclinic/config/RootApplicationContextConfig.java b/src/main/java/org/springframework/samples/petclinic/config/RootApplicationContextConfig.java
new file mode 100644
index 000000000..a0f598be7
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/config/RootApplicationContextConfig.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2002-2013 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.
+ */
+/*
+ * Copyright 2002-2013 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.samples.petclinic.config;
+
+import javax.annotation.PostConstruct;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.core.env.Environment;
+
+@Configuration
+@Import({BusinessConfig.class, ToolsConfig.class})
+public class RootApplicationContextConfig {
+
+ private static final Logger LOG = LoggerFactory.getLogger(RootApplicationContextConfig.class);
+
+ @Autowired
+ private Environment env;
+
+ /**
+ * Application custom initialization code.
+ *
+ * Spring profiles can be configured with a system property
+ * -Dspring.profiles.active=javaee
+ *
+ */
+ @PostConstruct
+ public void initApp() {
+ LOG.debug("Looking for Spring profiles...");
+ if (env.getActiveProfiles().length == 0) {
+ LOG.info("No Spring profile configured, running with default configuration.");
+ } else {
+ for (String profile : env.getActiveProfiles()) {
+ LOG.info("Detected Spring profile: {}", profile);
+ }
+ }
+ }
+
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/config/SharedJpaConfig.java b/src/main/java/org/springframework/samples/petclinic/config/SharedJpaConfig.java
new file mode 100644
index 000000000..893a222be
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/config/SharedJpaConfig.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2002-2013 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.
+ */
+/*
+ * Copyright 2002-2013 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.samples.petclinic.config;
+
+import javax.persistence.EntityManagerFactory;
+import javax.sql.DataSource;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
+import org.springframework.core.env.Environment;
+import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
+import org.springframework.orm.jpa.JpaTransactionManager;
+import org.springframework.orm.jpa.JpaVendorAdapter;
+import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
+import org.springframework.orm.jpa.vendor.Database;
+import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
+
+@Configuration
+@Profile({"jpa", "spring-data-jpa"})
+public class SharedJpaConfig {
+
+ @Autowired
+ private Environment env;
+
+ @Autowired
+ private DataSource dataSource;
+
+ @Bean
+ public EntityManagerFactory entityManagerFactory() {
+ LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
+ em.setDataSource(dataSource);
+ // gDickens: BOTH Persistence Unit and Packages to Scan are NOT compatible, persistenceUnit will win
+ em.setPersistenceUnitName("petclinic");
+ em.setPackagesToScan("org.springframework.samples.petclinic");
+ em.setJpaVendorAdapter(jpaVendorAdaper());
+ em.afterPropertiesSet();
+ return em.getObject();
+ }
+
+ @Bean
+ public JpaVendorAdapter jpaVendorAdaper() {
+ HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
+ // the 'database' parameter refers to the database dialect being used.
+ // By default, Hibernate will use a 'HSQL' dialect because 'jpa.database' has been set to 'HSQL'
+ // inside file spring/data-access.properties
+ vendorAdapter.setDatabase(env.getProperty("jpa.database", Database.class));
+ vendorAdapter.setShowSql(env.getProperty("jpa.showSql", Boolean.class));
+ return vendorAdapter;
+ }
+
+ @Bean(name="transactionManager")
+ public JpaTransactionManager jpaTransactionManager() {
+ JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
+ jpaTransactionManager.setEntityManagerFactory(entityManagerFactory());
+ return jpaTransactionManager;
+ }
+
+ @Bean
+ public PersistenceExceptionTranslationPostProcessor persistenceExceptionTranslationPostProcessor() {
+ return new PersistenceExceptionTranslationPostProcessor();
+ }
+
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/config/SpringDataJpaConfig.java b/src/main/java/org/springframework/samples/petclinic/config/SpringDataJpaConfig.java
new file mode 100644
index 000000000..dedd5f179
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/config/SpringDataJpaConfig.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2002-2013 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.
+ */
+/*
+ * Copyright 2002-2013 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.samples.petclinic.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+
+@Configuration
+@Profile("spring-data-jpa")
+@EnableJpaRepositories("org.springframework.samples.petclinic.repository.springdatajpa")
+public class SpringDataJpaConfig {
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/config/ToolsConfig.java b/src/main/java/org/springframework/samples/petclinic/config/ToolsConfig.java
new file mode 100644
index 000000000..e69da090e
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/config/ToolsConfig.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2002-2013 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.
+ */
+/*
+ * Copyright 2002-2013 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.samples.petclinic.config;
+
+import net.sf.ehcache.CacheManager;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.cache.ehcache.EhCacheCacheManager;
+import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Description;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.context.annotation.EnableMBeanExport;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.samples.petclinic.util.CallMonitoringAspect;
+
+@Configuration
+@EnableCaching // enables scanning for @Cacheable annotation
+@EnableMBeanExport
+@EnableAspectJAutoProxy
+public class ToolsConfig {
+
+ @Bean
+ @Description("Call monitoring aspect that monitors call count and call invocation time")
+ public CallMonitoringAspect callMonitor() {
+ return new CallMonitoringAspect();
+ }
+
+ @Bean
+ @Autowired
+ public EhCacheCacheManager ehCacheCacheManager(CacheManager cacheManager) {
+ EhCacheCacheManager ehCacheCacheManager = new EhCacheCacheManager();
+ ehCacheCacheManager.setCacheManager(cacheManager);
+ return ehCacheCacheManager;
+ }
+
+ @Bean
+ public EhCacheManagerFactoryBean cacheManager() {
+ EhCacheManagerFactoryBean ehCacheManager = new EhCacheManagerFactoryBean();
+ ehCacheManager.setConfigLocation(new ClassPathResource("cache/ehcache.xml"));
+ return ehCacheManager;
+ }
+}
diff --git a/src/main/resources/spring/business-config.xml b/src/main/resources/spring/business-config.xml
deleted file mode 100644
index 99cf4c1d3..000000000
--- a/src/main/resources/spring/business-config.xml
+++ /dev/null
@@ -1,96 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/main/resources/spring/data-access.properties b/src/main/resources/spring/data-access.properties
index c1cc3cefd..e22ce1df6 100644
--- a/src/main/resources/spring/data-access.properties
+++ b/src/main/resources/spring/data-access.properties
@@ -13,8 +13,8 @@ jdbc.username=sa
jdbc.password=
# Properties that control the population of schema and data for a new data source
-jdbc.initLocation=classpath:db/hsqldb/initDB.sql
-jdbc.dataLocation=classpath:db/hsqldb/populateDB.sql
+jdbc.initLocation=db/hsqldb/initDB.sql
+jdbc.dataLocation=db/hsqldb/populateDB.sql
# Property that determines which database to use with an AbstractJpaVendorAdapter
jpa.database=HSQL
diff --git a/src/main/resources/spring/datasource-config.xml b/src/main/resources/spring/datasource-config.xml
deleted file mode 100644
index f74129963..000000000
--- a/src/main/resources/spring/datasource-config.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/main/resources/spring/mvc-core-config.xml b/src/main/resources/spring/mvc-core-config.xml
deleted file mode 100644
index 170fbdba1..000000000
--- a/src/main/resources/spring/mvc-core-config.xml
+++ /dev/null
@@ -1,66 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/main/resources/spring/mvc-view-config.xml b/src/main/resources/spring/mvc-view-config.xml
deleted file mode 100644
index 4413f0195..000000000
--- a/src/main/resources/spring/mvc-view-config.xml
+++ /dev/null
@@ -1,64 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/main/resources/spring/tools-config.xml b/src/main/resources/spring/tools-config.xml
deleted file mode 100644
index 1be7e3b6c..000000000
--- a/src/main/resources/spring/tools-config.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
index 360e3698a..2fcd59eba 100644
--- a/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -28,13 +28,18 @@ http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
-->
-
- contextConfigLocation
- classpath:spring/business-config.xml, classpath:spring/tools-config.xml
-
+
+ contextClass
+ org.springframework.web.context.support.AnnotationConfigWebApplicationContext
+
+
+ contextConfigLocation
+ org.springframework.samples.petclinic.config.RootApplicationContextConfig
+
+
org.springframework.web.context.ContextLoaderListener
@@ -46,10 +51,14 @@ http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
petclinic
org.springframework.web.servlet.DispatcherServlet
-
- contextConfigLocation
- classpath:spring/mvc-core-config.xml
-
+
+ contextClass
+ org.springframework.web.context.support.AnnotationConfigWebApplicationContext
+
+
+ contextConfigLocation
+ org.springframework.samples.petclinic.config.MvcCoreConfig
+
1
diff --git a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJdbcTests.java b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJdbcTests.java
index 49e57ea40..1543596b0 100644
--- a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJdbcTests.java
+++ b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJdbcTests.java
@@ -16,6 +16,7 @@
package org.springframework.samples.petclinic.service;
import org.junit.runner.RunWith;
+import org.springframework.samples.petclinic.config.BusinessConfig;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -27,7 +28,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Thomas Risberg
* @author Michael Isvy
*/
-@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
+@ContextConfiguration(classes = BusinessConfig.class)
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("jdbc")
public class ClinicServiceJdbcTests extends AbstractClinicServiceTests {
diff --git a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJpaTests.java b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJpaTests.java
index e024f21fd..2f5c9e3fc 100644
--- a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJpaTests.java
+++ b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJpaTests.java
@@ -2,6 +2,7 @@
package org.springframework.samples.petclinic.service;
import org.junit.runner.RunWith;
+import org.springframework.samples.petclinic.config.BusinessConfig;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -15,7 +16,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Michael Isvy
*/
-@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
+@ContextConfiguration(classes = BusinessConfig.class)
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("jpa")
public class ClinicServiceJpaTests extends AbstractClinicServiceTests {
diff --git a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceSpringDataJpaTests.java b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceSpringDataJpaTests.java
index e01dda551..2cbd73c9e 100644
--- a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceSpringDataJpaTests.java
+++ b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceSpringDataJpaTests.java
@@ -2,6 +2,7 @@
package org.springframework.samples.petclinic.service;
import org.junit.runner.RunWith;
+import org.springframework.samples.petclinic.config.BusinessConfig;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -12,7 +13,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Michael Isvy
*/
-@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
+@ContextConfiguration(classes = BusinessConfig.class)
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("spring-data-jpa")
public class ClinicServiceSpringDataJpaTests extends AbstractClinicServiceTests {
diff --git a/src/test/java/org/springframework/samples/petclinic/web/VisitsViewTests-config.xml b/src/test/java/org/springframework/samples/petclinic/web/VisitsViewTests-config.xml
deleted file mode 100644
index 8458ba2ec..000000000
--- a/src/test/java/org/springframework/samples/petclinic/web/VisitsViewTests-config.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/src/test/java/org/springframework/samples/petclinic/web/VisitsViewTests.java b/src/test/java/org/springframework/samples/petclinic/web/VisitsViewTests.java
index ace89a019..8372f60af 100644
--- a/src/test/java/org/springframework/samples/petclinic/web/VisitsViewTests.java
+++ b/src/test/java/org/springframework/samples/petclinic/web/VisitsViewTests.java
@@ -28,8 +28,11 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
+import org.springframework.samples.petclinic.config.BusinessConfig;
+import org.springframework.samples.petclinic.config.MvcCoreConfig;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.ContextHierarchy;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
@@ -44,7 +47,9 @@ import org.springframework.web.context.WebApplicationContext;
*/
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
-@ContextConfiguration("VisitsViewTests-config.xml")
+@ContextHierarchy({
+ @ContextConfiguration(classes = BusinessConfig.class),
+ @ContextConfiguration(classes = MvcCoreConfig.class)})
@ActiveProfiles("jdbc")
public class VisitsViewTests {