mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 21:35:50 +00:00
Merge 8230b2a6fe
into 8929d373ec
This commit is contained in:
commit
ccdeff7cd6
27 changed files with 995 additions and 357 deletions
1
pom.xml
1
pom.xml
|
@ -168,7 +168,6 @@
|
|||
<groupId>org.apache.tomcat</groupId>
|
||||
<artifactId>tomcat-jdbc</artifactId>
|
||||
<version>${tomcat-jdbc.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Logging with SLF4J & LogBack -->
|
||||
|
|
22
readme.md
22
readme.md
|
@ -52,16 +52,16 @@ File -> Import -> Maven -> Existing Maven project
|
|||
<td>Spring MVC- Atom integration</td>
|
||||
<td>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/web/VetsAtomView.java">VetsAtomView.java</a>
|
||||
<a href="/src/main/resources/spring/mvc-view-config.xml">mvc-view-config.xml</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/config/MvcViewConfig.java">MvcViewConfig.java</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Spring MVC - XML integration</td>
|
||||
<td><a href="/src/main/resources/spring/mvc-view-config.xml">mvc-view-config.xml</a></td>
|
||||
<td><a href="/src/main/java/org/springframework/samples/petclinic/config/MvcViewConfig.jav">MvcViewConfig.java</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Spring MVC - ContentNegotiatingViewResolver</td>
|
||||
<td><a href="/src/main/resources/spring/mvc-view-config.xml">mvc-view-config.xml</a></td>
|
||||
<td><a href="/src/main/java/org/springframework/samples/petclinic/config/MvcViewConfig.jav">MvcViewConfig.java</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Spring MVC Test Framework</td>
|
||||
|
@ -77,7 +77,7 @@ File -> Import -> Maven -> Existing Maven project
|
|||
<td>webjars</td>
|
||||
<td>
|
||||
<a href="/pom.xml">webjars declaration inside pom.xml</a> <br />
|
||||
<a href="/src/main/resources/spring/mvc-core-config.xml#L24">Resource mapping in Spring configuration</a> <br />
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/config/MvcCoreConfig.javal#L108">Resource mapping in Spring configuration</a> <br />
|
||||
<a href="/src/main/webapp/WEB-INF/jsp/fragments/headTag.jsp#L12">sample usage in JSP</a></td>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -109,21 +109,21 @@ File -> Import -> Maven -> Existing Maven project
|
|||
<tr>
|
||||
<td>Transactions</td>
|
||||
<td>
|
||||
<a href="/src/main/resources/spring/business-config.xml">business-config.xml</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/config/BusinessConfig.java">BusinessConfig.java</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java">ClinicServiceImpl.java</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Cache</td>
|
||||
<td>
|
||||
<a href="/src/main/resources/spring/tools-config.xml">tools-config.xml</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/config/ToolsConfig.java">ToolsConfig.java</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java">ClinicServiceImpl.java</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Bean Profiles</td>
|
||||
<td>
|
||||
<a href="/src/main/resources/spring/business-config.xml">business-config.xml</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/config/JdbcConfig.java">JdbcConfig.java</a>
|
||||
<a href="/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJdbcTests.java">ClinicServiceJdbcTests.java</a>
|
||||
<a href="/src/main/webapp/WEB-INF/web.xml">web.xml</a>
|
||||
</td>
|
||||
|
@ -131,19 +131,21 @@ File -> Import -> Maven -> Existing Maven project
|
|||
<tr>
|
||||
<td>JdbcTemplate</td>
|
||||
<td>
|
||||
<a href="/src/main/resources/spring/business-config.xml">business-config.xml</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/config/JdbcConfig.java">JdbcConfig.java</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/repository/jdbc">jdbc folder</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>JPA</td>
|
||||
<td>
|
||||
<a href="/src/main/resources/spring/business-config.xml">business-config.xml</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/config/SharedJpaConfig.java">SharedJpaConfig.java</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/config/JpaConfig.java">JpaConfig.java</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/repository/jpa">jpa folder</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Spring Data JPA</td>
|
||||
<td>
|
||||
<a href="/src/main/resources/spring/business-config.xml">business-config.xml</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/config/SharedJpaConfig.java">SharedJpaConfig.java</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/config/SpringDataJpaConfig.java">SpringDataJpaConfig.java</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa">springdatajpa folder</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 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.
|
||||
*
|
||||
* <p>
|
||||
* View name resolved using bean of type InternalResourceViewResolver
|
||||
* (declared in {@link MvcViewConfig}).
|
||||
*/
|
||||
@Override
|
||||
public void configureHandlerExceptionResolvers(
|
||||
List<HandlerExceptionResolver> 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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<ViewResolver> viewResolvers = new ArrayList<ViewResolver>();
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
|
||||
|
||||
}
|
|
@ -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<String, Object> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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.
|
||||
* <p/>
|
||||
* Spring profiles can be configured with a system property
|
||||
* -Dspring.profiles.active=javaee
|
||||
* <p/>
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Repository and Service layers
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<!-- ========================= RESOURCE DEFINITIONS ========================= -->
|
||||
|
||||
<!-- import the dataSource definition -->
|
||||
<import resource="datasource-config.xml"/>
|
||||
|
||||
<context:component-scan
|
||||
base-package="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) -->
|
||||
<context:property-placeholder location="classpath:spring/data-access.properties" system-properties-mode="OVERRIDE"/>
|
||||
|
||||
<!-- enables scanning for @Transactional annotations -->
|
||||
<tx:annotation-driven />
|
||||
|
||||
|
||||
<!-- ================== 3 Profiles to choose from ===================
|
||||
- jdbc (uses Spring" JdbcTemplate)
|
||||
- jpa
|
||||
- spring-data-jpa
|
||||
=============================================================================-->
|
||||
|
||||
<beans profile="jpa,spring-data-jpa">
|
||||
<!-- JPA EntityManagerFactory -->
|
||||
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
|
||||
p:dataSource-ref="dataSource">
|
||||
<property name="jpaVendorAdapter">
|
||||
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
|
||||
p:database="${jpa.database}" p:showSql="${jpa.showSql}"/>
|
||||
<!-- 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
|
||||
|
||||
-->
|
||||
</property>
|
||||
<!-- gDickens: BOTH Persistence Unit and Packages to Scan are NOT compatible, persistenceUnit will win -->
|
||||
<property name="persistenceUnitName" value="petclinic"/>
|
||||
<property name="packagesToScan" value="org.springframework.samples.petclinic"/>
|
||||
</bean>
|
||||
|
||||
<!-- Transaction manager for a single JPA EntityManagerFactory (alternative to JTA) -->
|
||||
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
|
||||
p:entityManagerFactory-ref="entityManagerFactory"/>
|
||||
|
||||
|
||||
<!--
|
||||
Post-processor to perform exception translation on @Repository classes (from native
|
||||
exceptions such as JPA PersistenceExceptions to Spring's DataAccessException hierarchy).
|
||||
-->
|
||||
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
|
||||
|
||||
</beans>
|
||||
|
||||
<beans profile="jdbc">
|
||||
<!-- Transaction manager for a single JDBC DataSource (alternative to JTA) -->
|
||||
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
|
||||
p:dataSource-ref="dataSource"/>
|
||||
|
||||
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
|
||||
<constructor-arg ref="dataSource"/>
|
||||
</bean>
|
||||
|
||||
<bean id="namedParameterJdbcTemplate"
|
||||
class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
|
||||
<constructor-arg ref="dataSource"/>
|
||||
</bean>
|
||||
|
||||
<context:component-scan base-package="org.springframework.samples.petclinic.repository.jdbc"/>
|
||||
</beans>
|
||||
|
||||
<beans profile="jpa">
|
||||
<!--
|
||||
Loads JPA beans
|
||||
Will automatically be transactional due to @Transactional.
|
||||
EntityManager will be auto-injected due to @PersistenceContext.
|
||||
PersistenceExceptions will be auto-translated due to @Repository.
|
||||
-->
|
||||
<context:component-scan base-package="org.springframework.samples.petclinic.repository.jpa"/>
|
||||
</beans>
|
||||
|
||||
<beans profile="spring-data-jpa">
|
||||
<jpa:repositories base-package="org.springframework.samples.petclinic.repository.springdatajpa"/>
|
||||
</beans>
|
||||
</beans>
|
|
@ -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
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Application context definition for PetClinic Datasource.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
xmlns:jee="http://www.springframework.org/schema/jee"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/jdbc
|
||||
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
|
||||
http://www.springframework.org/schema/jee
|
||||
http://www.springframework.org/schema/jee/spring-jee.xsd">
|
||||
|
||||
<!-- ========================= DATASOURCE DEFINITION ========================= -->
|
||||
|
||||
<!-- Configurer that replaces ${...} placeholders with values from a properties file -->
|
||||
<!-- (in this case, JDBC-related settings for the dataSource definition below) -->
|
||||
<context:property-placeholder location="classpath:spring/data-access.properties" system-properties-mode="OVERRIDE"/>
|
||||
|
||||
<!-- DataSource configuration for the tomcat jdbc connection pool
|
||||
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/-->
|
||||
<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource"
|
||||
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
|
||||
p:username="${jdbc.username}" p:password="${jdbc.password}"/>
|
||||
|
||||
<!-- Database initializer. If any of the script fails, the initialization stops. -->
|
||||
<!-- As an alternative, for embedded databases see <jdbc:embedded-database/>. -->
|
||||
<jdbc:initialize-database data-source="dataSource">
|
||||
<jdbc:script location="${jdbc.initLocation}"/>
|
||||
<jdbc:script location="${jdbc.dataLocation}"/>
|
||||
</jdbc:initialize-database>
|
||||
|
||||
<beans profile="javaee" >
|
||||
<!-- JNDI DataSource for JEE environments -->
|
||||
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/petclinic"/>
|
||||
</beans>
|
||||
</beans>
|
|
@ -1,66 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
- DispatcherServlet application context for PetClinic's web tier.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/mvc
|
||||
http://www.springframework.org/schema/mvc/spring-mvc.xsd
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<import resource="mvc-view-config.xml"/>
|
||||
|
||||
<!--
|
||||
- POJOs labeled with the @Controller and @Service annotations are auto-detected.
|
||||
-->
|
||||
<context:component-scan
|
||||
base-package="org.springframework.samples.petclinic.web"/>
|
||||
|
||||
<mvc:annotation-driven conversion-service="conversionService"/>
|
||||
|
||||
<!-- 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) -->
|
||||
<mvc:resources mapping="/resources/**" location="/resources/"/>
|
||||
|
||||
<!-- uses WebJars so Javascript and CSS libs can be declared as Maven dependencies (Bootstrap, jQuery...) -->
|
||||
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
|
||||
|
||||
<mvc:view-controller path="/" view-name="welcome" />
|
||||
|
||||
<!-- serve static resources (*.html, ...) from src/main/webapp/ -->
|
||||
<mvc:default-servlet-handler/>
|
||||
|
||||
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
|
||||
<property name="formatters">
|
||||
<set>
|
||||
<bean class="org.springframework.samples.petclinic.web.PetTypeFormatter"/>
|
||||
</set>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!--
|
||||
- Message source for this context, loaded from localized "messages_xx" files.
|
||||
- Files are stored inside src/main/resources
|
||||
-->
|
||||
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"
|
||||
p:basename="messages/messages"/>
|
||||
|
||||
<!--
|
||||
- This bean resolves specific types of exceptions to corresponding logical
|
||||
- view names for error views.
|
||||
-->
|
||||
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
|
||||
<!-- view name resolved using bean of type InternalResourceViewResolver (declared in mvc-view-config.xml) -->
|
||||
<property name="defaultErrorView" value="exception"/>
|
||||
<!-- results into 'WEB-INF/jsp/exception.jsp' -->
|
||||
<property name="warnLogCategory" value="warn"/>
|
||||
<!-- needed otherwise exceptions won't be logged anywhere -->
|
||||
</bean>
|
||||
|
||||
</beans>
|
|
@ -1,64 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
- DispatcherServlet application context for PetClinic's web tier.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:oxm="http://www.springframework.org/schema/oxm"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/oxm
|
||||
http://www.springframework.org/schema/oxm/spring-oxm.xsd
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<!--
|
||||
- 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.
|
||||
-->
|
||||
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
|
||||
<property name="contentNegotiationManager" ref="cnManager"/>
|
||||
|
||||
<property name="viewResolvers">
|
||||
<list>
|
||||
<!-- Default viewClass: JSTL view (JSP with html output) -->
|
||||
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||
<!-- Example: a logical view name of 'vets' is mapped to '/WEB-INF/jsp/vets.jsp' -->
|
||||
<property name="prefix" value="/WEB-INF/jsp/"/>
|
||||
<property name="suffix" value=".jsp"/>
|
||||
</bean>
|
||||
|
||||
<!-- Used here for 'xml' and 'atom' views -->
|
||||
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- Simple strategy: only path extension is taken into account -->
|
||||
<bean id="cnManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
|
||||
<property name="favorPathExtension" value="true"/>
|
||||
<property name="ignoreAcceptHeader" value="true"/>
|
||||
<property name="defaultContentType" value="text/html"/>
|
||||
|
||||
<property name="mediaTypes">
|
||||
<map>
|
||||
<entry key="html" value="text/html" />
|
||||
<entry key="xml" value="application/xml" />
|
||||
<entry key="atom" value="application/atom+xml" />
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- Renders an Atom feed of the visits. Used by the BeanNameViewResolver -->
|
||||
<bean id="vets/vetList.atom" class="org.springframework.samples.petclinic.web.VetsAtomView"/>
|
||||
|
||||
<!-- Renders an XML view. Used by the BeanNameViewResolver -->
|
||||
<bean id="vets/vetList.xml" class="org.springframework.web.servlet.view.xml.MarshallingView">
|
||||
<property name="marshaller" ref="marshaller"/>
|
||||
</bean>
|
||||
|
||||
<oxm:jaxb2-marshaller id="marshaller">
|
||||
<!-- Object-XML mapping declared using annotations inside 'Vets' -->
|
||||
<oxm:class-to-be-bound name="org.springframework.samples.petclinic.model.Vets"/>
|
||||
</oxm:jaxb2-marshaller>
|
||||
|
||||
</beans>
|
|
@ -1,49 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Application context definition for PetClinic on JPA.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:cache="http://www.springframework.org/schema/cache"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop.xsd
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/cache
|
||||
http://www.springframework.org/schema/cache/spring-cache.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<!--
|
||||
Simply defining this bean will cause requests to owner names to be saved.
|
||||
This aspect is defined in petclinic.jar's META-INF/aop.xml file.
|
||||
Note that we can dependency inject this bean like any other bean.
|
||||
-->
|
||||
<aop:aspectj-autoproxy>
|
||||
<aop:include name="callMonitor"/>
|
||||
</aop:aspectj-autoproxy>
|
||||
|
||||
<!-- Call monitoring aspect that monitors call count and call invocation time -->
|
||||
<bean id="callMonitor" class="org.springframework.samples.petclinic.util.CallMonitoringAspect"/>
|
||||
|
||||
<!--
|
||||
Exporter that exposes the CallMonitoringAspect via JMX,
|
||||
based on the @ManagedResource, @ManagedAttribute, and @ManagedOperation annotations.
|
||||
-->
|
||||
<context:mbean-export/>
|
||||
|
||||
<!-- enables scanning for @Cacheable annotation -->
|
||||
<cache:annotation-driven/>
|
||||
|
||||
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
|
||||
<property name="cacheManager" ref="ehcache"/>
|
||||
</bean>
|
||||
|
||||
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
|
||||
<property name="configLocation" value="classpath:cache/ehcache.xml"/>
|
||||
</bean>
|
||||
|
||||
|
||||
</beans>
|
|
@ -28,13 +28,18 @@ http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
|||
-->
|
||||
|
||||
<!--
|
||||
- Location of the XML file that defines the root application context.
|
||||
- Location of the Java configuration that defines the root application context.
|
||||
- Applied by ContextLoaderListener.
|
||||
-->
|
||||
<context-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>classpath:spring/business-config.xml, classpath:spring/tools-config.xml</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>contextClass</param-name>
|
||||
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>org.springframework.samples.petclinic.config.RootApplicationContextConfig</param-value>
|
||||
</context-param>
|
||||
|
||||
|
||||
<listener>
|
||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||
|
@ -46,10 +51,14 @@ http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
|||
<servlet>
|
||||
<servlet-name>petclinic</servlet-name>
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>classpath:spring/mvc-core-config.xml</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>contextClass</param-name>
|
||||
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>org.springframework.samples.petclinic.config.MvcCoreConfig</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
- DispatcherServlet application context for PetClinic's web tier.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<import resource="classpath:spring/business-config.xml"/>
|
||||
<import resource="classpath:spring/mvc-core-config.xml"/>
|
||||
|
||||
</beans>
|
|
@ -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 {
|
||||
|
||||
|
|
Loading…
Reference in a new issue