mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-04-24 11:22:48 +00:00
#164 Spring Boot version of Petclinic ready to deploy to an external web container (ie Tomcat)
This commit is contained in:
parent
76a4ca330b
commit
a6e81a51a0
66 changed files with 385 additions and 1964 deletions
181
pom.xml
181
pom.xml
|
@ -3,9 +3,13 @@
|
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.springframework.samples</groupId>
|
||||
<artifactId>spring-petclinic</artifactId>
|
||||
<version>4.2.5-SNAPSHOT</version>
|
||||
|
||||
<artifactId>springboot-petclinic</artifactId>
|
||||
<version>1.3.5-SNAPSHOT</version>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>1.3.5.RELEASE</version>
|
||||
</parent>
|
||||
<name>petclinic</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
|
@ -16,16 +20,12 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
<!-- Spring -->
|
||||
<spring-io-platform.version>2.0.3.RELEASE</spring-io-platform.version>
|
||||
<spring-data-jdbc.version>1.1.0.RELEASE</spring-data-jdbc.version>
|
||||
|
||||
|
||||
<!-- Java EE / Java SE dependencies -->
|
||||
<tomcat.version>7.0.59</tomcat.version>
|
||||
|
||||
<!-- Test -->
|
||||
<assertj.version>2.2.0</assertj.version>
|
||||
<hamcrest.version>1.3</hamcrest.version>
|
||||
|
||||
<!-- Dates -->
|
||||
<jodatime-hibernate.version>1.3</jodatime-hibernate.version>
|
||||
|
@ -43,89 +43,29 @@
|
|||
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<!-- Import the maven Spring IO Platform Bill Of Materials (BOM) -->
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.spring.platform</groupId>
|
||||
<artifactId>platform-bom</artifactId>
|
||||
<version>${spring-io-platform.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jadira.usertype</groupId>
|
||||
<artifactId>usertype.core</artifactId>
|
||||
<version>${jadira-usertype-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat</groupId>
|
||||
<artifactId>tomcat-servlet-api</artifactId>
|
||||
<version>${tomcat.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>javax.servlet.jsp-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat</groupId>
|
||||
<artifactId>tomcat-jasper-el</artifactId>
|
||||
<version>${tomcat.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp.jstl</groupId>
|
||||
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.taglibs</groupId>
|
||||
<artifactId>taglibs-standard-jstlel</artifactId>
|
||||
</dependency>
|
||||
<!-- JSon -->
|
||||
<dependency>
|
||||
<groupId>com.jayway.jsonpath</groupId>
|
||||
<artifactId>json-path</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- SPRING, SPRING, SPRINGITY SPRING -->
|
||||
<!-- Spring et Spring Boot dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-cache</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-jdbc-core</artifactId>
|
||||
<version>${spring-data-jdbc.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>*</artifactId>
|
||||
</exclusion>
|
||||
<!-- because Spring Data usually comes with a slightly older version of Spring -->
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- used for EhCacheCacheManager -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
|
@ -135,6 +75,33 @@
|
|||
<artifactId>spring-oxm</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<!-- Tomcat -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-jasper</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- JSon -->
|
||||
<dependency>
|
||||
<groupId>com.jayway.jsonpath</groupId>
|
||||
<artifactId>json-path</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- used for EhCacheCacheManager -->
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
|
@ -181,6 +148,11 @@
|
|||
<artifactId>joda-time-jsptags</artifactId>
|
||||
<version>${jodatime-jsptags.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jadira.usertype</groupId>
|
||||
<artifactId>usertype.core</artifactId>
|
||||
<version>${jadira-usertype-core.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Databases - Uses HSQL by default -->
|
||||
<dependency>
|
||||
|
@ -196,20 +168,7 @@
|
|||
<version>${mysql-driver.version}</version>
|
||||
</dependency-->
|
||||
|
||||
<!-- HIBERNATE -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-entitymanager</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-ehcache</artifactId>
|
||||
</dependency>
|
||||
<!-- EhCache -->
|
||||
<dependency>
|
||||
<groupId>net.sf.ehcache</groupId>
|
||||
<artifactId>ehcache</artifactId>
|
||||
|
@ -222,32 +181,12 @@
|
|||
</dependency>
|
||||
|
||||
<!-- Test Artifacts -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Dandelion -->
|
||||
<dependency>
|
||||
|
@ -276,16 +215,14 @@
|
|||
<!-- Maven plugin versions are mentioned in order to guarantee the build reproducibility in the long term -->
|
||||
<build>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
<testResources>
|
||||
<testResource>
|
||||
<!-- declared explicitly so Spring config files can be placed next to their corresponding JUnit test class -->
|
||||
<directory>${project.basedir}/src/test/java</directory>
|
||||
</testResource>
|
||||
<testResource>
|
||||
<directory>${project.basedir}/src/test/resources</directory>
|
||||
</testResource>
|
||||
</testResources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<classifier>boot</classifier>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.samples.petclinic;
|
||||
|
||||
import com.github.dandelion.core.web.DandelionFilter;
|
||||
import com.github.dandelion.core.web.DandelionServlet;
|
||||
import net.sf.ehcache.config.CacheConfiguration;
|
||||
import net.sf.ehcache.config.PersistenceConfiguration;
|
||||
import net.sf.ehcache.config.PersistenceConfiguration.Strategy;
|
||||
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.embedded.FilterRegistrationBean;
|
||||
import org.springframework.boot.context.embedded.ServletRegistrationBean;
|
||||
import org.springframework.boot.context.web.SpringBootServletInitializer;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.ehcache.EhCacheCacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
|
||||
import org.springframework.samples.petclinic.model.Vets;
|
||||
import org.springframework.web.servlet.view.xml.MarshallingView;
|
||||
|
||||
/**
|
||||
* PetClinic Spring Boot Application.
|
||||
*
|
||||
*/
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@EnableCaching
|
||||
@ComponentScan
|
||||
public class PetClinicApplication extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(PetClinicApplication.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright 2002-2016 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.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
|
||||
import org.springframework.samples.petclinic.model.Vets;
|
||||
import org.springframework.web.servlet.view.BeanNameViewResolver;
|
||||
import org.springframework.web.servlet.view.xml.MarshallingView;
|
||||
|
||||
/**
|
||||
*
|
||||
* {@link BeanNameViewResolver} is used to resolve the Atom and Xml views. So, the
|
||||
* following beans names must match the name of the JSP you want to override and the
|
||||
* file extension will indicate which bean to use for resolving.
|
||||
*
|
||||
*/
|
||||
@Configuration
|
||||
public class CustomViewsConfiguration {
|
||||
|
||||
@Bean(name = "vets/vetList.xml")
|
||||
public MarshallingView vetsXmlView() {
|
||||
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
|
||||
marshaller.setClassesToBeBound(Vets.class);
|
||||
return new MarshallingView(marshaller);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright 2002-2016 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 com.github.dandelion.core.web.DandelionFilter;
|
||||
import com.github.dandelion.core.web.DandelionServlet;
|
||||
import com.github.dandelion.datatables.core.web.filter.DatatablesFilter;
|
||||
import org.springframework.boot.context.embedded.FilterRegistrationBean;
|
||||
import org.springframework.boot.context.embedded.ServletRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Description;
|
||||
|
||||
/**
|
||||
* Java configuration for the Dandelion datatables component.
|
||||
*
|
||||
* @author Antoine Rey
|
||||
*/
|
||||
@Configuration
|
||||
public class DandelionConfig {
|
||||
|
||||
@Bean
|
||||
@Description("Dandelion filter definition and mapping")
|
||||
public FilterRegistrationBean filterRegistrationBean() {
|
||||
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
|
||||
filterRegistrationBean.setFilter(new DandelionFilter());
|
||||
return filterRegistrationBean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Description("Dandelion-Datatables filter, used for basic export")
|
||||
public FilterRegistrationBean datatablesRegistrationBean() {
|
||||
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
|
||||
filterRegistrationBean.setFilter(new DatatablesFilter());
|
||||
return filterRegistrationBean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ServletRegistrationBean servletRegistrationBean() {
|
||||
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean();
|
||||
servletRegistrationBean.setServlet(new DandelionServlet());
|
||||
servletRegistrationBean.addUrlMappings("/dandelion-assets/*");
|
||||
servletRegistrationBean.setName("dandelionServlet");
|
||||
return servletRegistrationBean;
|
||||
}
|
||||
}
|
|
@ -103,7 +103,9 @@ public class Owner extends Person {
|
|||
}
|
||||
|
||||
public void addPet(Pet pet) {
|
||||
getPetsInternal().add(pet);
|
||||
if (pet.isNew()) {
|
||||
getPetsInternal().add(pet);
|
||||
}
|
||||
pet.setOwner(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -110,4 +110,8 @@ public class Pet extends NamedEntity {
|
|||
visit.setPet(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,9 @@ package org.springframework.samples.petclinic.repository;
|
|||
import java.util.Collection;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.samples.petclinic.model.BaseEntity;
|
||||
import org.springframework.samples.petclinic.model.Owner;
|
||||
|
||||
|
@ -30,35 +33,31 @@ import org.springframework.samples.petclinic.model.Owner;
|
|||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
public interface OwnerRepository {
|
||||
public interface OwnerRepository extends Repository<Owner, Integer> {
|
||||
|
||||
/**
|
||||
* Retrieve <code>Owner</code>s from the data store by last name, returning all owners whose last name <i>starts</i>
|
||||
* with the given name.
|
||||
*
|
||||
* Retrieve {@link Owner}s from the data store by last name, returning all owners
|
||||
* whose last name <i>starts</i> with the given name.
|
||||
* @param lastName Value to search for
|
||||
* @return a <code>Collection</code> of matching <code>Owner</code>s (or an empty <code>Collection</code> if none
|
||||
* @return a Collection of matching {@link Owner}s (or an empty Collection if none
|
||||
* found)
|
||||
*/
|
||||
Collection<Owner> findByLastName(String lastName) throws DataAccessException;
|
||||
@Query("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName%")
|
||||
Collection<Owner> findByLastName(@Param("lastName") String lastName);
|
||||
|
||||
/**
|
||||
* Retrieve an <code>Owner</code> from the data store by id.
|
||||
*
|
||||
* Retrieve an {@link Owner} from the data store by id.
|
||||
* @param id the id to search for
|
||||
* @return the <code>Owner</code> if found
|
||||
* @throws org.springframework.dao.DataRetrievalFailureException if not found
|
||||
* @return the {@link Owner} if found
|
||||
*/
|
||||
Owner findById(int id) throws DataAccessException;
|
||||
|
||||
@Query("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id")
|
||||
Owner findById(@Param("id") int id);
|
||||
|
||||
/**
|
||||
* Save an <code>Owner</code> to the data store, either inserting or updating it.
|
||||
*
|
||||
* @param owner the <code>Owner</code> to save
|
||||
* @see BaseEntity#isNew
|
||||
* Save an {@link Owner} to the data store, either inserting or updating it.
|
||||
* @param owner the {@link Owner} to save
|
||||
*/
|
||||
void save(Owner owner) throws DataAccessException;
|
||||
void save(Owner owner);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ package org.springframework.samples.petclinic.repository;
|
|||
import java.util.List;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.samples.petclinic.model.BaseEntity;
|
||||
import org.springframework.samples.petclinic.model.Pet;
|
||||
import org.springframework.samples.petclinic.model.PetType;
|
||||
|
@ -31,30 +33,27 @@ import org.springframework.samples.petclinic.model.PetType;
|
|||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
public interface PetRepository {
|
||||
public interface PetRepository extends Repository<Pet, Integer> {
|
||||
|
||||
/**
|
||||
* Retrieve all <code>PetType</code>s from the data store.
|
||||
*
|
||||
* @return a <code>Collection</code> of <code>PetType</code>s
|
||||
* Retrieve all {@link PetType}s from the data store.
|
||||
* @return a Collection of {@link PetType}s.
|
||||
*/
|
||||
List<PetType> findPetTypes() throws DataAccessException;
|
||||
@Query("SELECT ptype FROM PetType ptype ORDER BY ptype.name")
|
||||
List<PetType> findPetTypes();
|
||||
|
||||
/**
|
||||
* Retrieve a <code>Pet</code> from the data store by id.
|
||||
*
|
||||
* Retrieve a {@link Pet} from the data store by id.
|
||||
* @param id the id to search for
|
||||
* @return the <code>Pet</code> if found
|
||||
* @throws org.springframework.dao.DataRetrievalFailureException if not found
|
||||
* @return the {@link Pet} if found
|
||||
*/
|
||||
Pet findById(int id) throws DataAccessException;
|
||||
Pet findById(int id);
|
||||
|
||||
/**
|
||||
* Save a <code>Pet</code> to the data store, either inserting or updating it.
|
||||
*
|
||||
* @param pet the <code>Pet</code> to save
|
||||
* @see BaseEntity#isNew
|
||||
* Save a {@link Pet} to the data store, either inserting or updating it.
|
||||
* @param pet the {@link Pet} to save
|
||||
*/
|
||||
void save(Pet pet) throws DataAccessException;
|
||||
void save(Pet pet);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.springframework.samples.petclinic.repository;
|
|||
import java.util.Collection;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.samples.petclinic.model.Vet;
|
||||
|
||||
/**
|
||||
|
@ -29,7 +30,7 @@ import org.springframework.samples.petclinic.model.Vet;
|
|||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
public interface VetRepository {
|
||||
public interface VetRepository extends Repository<Vet, Integer> {
|
||||
|
||||
/**
|
||||
* Retrieve all <code>Vet</code>s from the data store.
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.springframework.samples.petclinic.repository;
|
|||
import java.util.List;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.samples.petclinic.model.BaseEntity;
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
|
||||
|
@ -30,7 +31,7 @@ import org.springframework.samples.petclinic.model.Visit;
|
|||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
public interface VisitRepository {
|
||||
public interface VisitRepository extends Repository<Visit, Integer> {
|
||||
|
||||
/**
|
||||
* Save a <code>Visit</code> to the data store, either inserting or updating it.
|
||||
|
|
|
@ -1,158 +0,0 @@
|
|||
/*
|
||||
* 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.repository.jdbc;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
|
||||
import org.springframework.orm.ObjectRetrievalFailureException;
|
||||
import org.springframework.samples.petclinic.model.Owner;
|
||||
import org.springframework.samples.petclinic.model.Pet;
|
||||
import org.springframework.samples.petclinic.model.PetType;
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||
import org.springframework.samples.petclinic.util.EntityUtils;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* A simple JDBC-based implementation of the {@link OwnerRepository} interface.
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Rob Harrop
|
||||
* @author Sam Brannen
|
||||
* @author Thomas Risberg
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@Repository
|
||||
public class JdbcOwnerRepositoryImpl implements OwnerRepository {
|
||||
|
||||
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
||||
|
||||
private SimpleJdbcInsert insertOwner;
|
||||
|
||||
@Autowired
|
||||
public JdbcOwnerRepositoryImpl(DataSource dataSource, NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
|
||||
|
||||
this.insertOwner = new SimpleJdbcInsert(dataSource)
|
||||
.withTableName("owners")
|
||||
.usingGeneratedKeyColumns("id");
|
||||
|
||||
this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads {@link Owner Owners} from the data store by last name, returning all owners whose last name <i>starts</i> with
|
||||
* the given name; also loads the {@link Pet Pets} and {@link Visit Visits} for the corresponding owners, if not
|
||||
* already loaded.
|
||||
*/
|
||||
@Override
|
||||
public Collection<Owner> findByLastName(String lastName) throws DataAccessException {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("lastName", lastName + "%");
|
||||
List<Owner> owners = this.namedParameterJdbcTemplate.query(
|
||||
"SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE last_name like :lastName",
|
||||
params,
|
||||
BeanPropertyRowMapper.newInstance(Owner.class)
|
||||
);
|
||||
loadOwnersPetsAndVisits(owners);
|
||||
return owners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the {@link Owner} with the supplied <code>id</code>; also loads the {@link Pet Pets} and {@link Visit Visits}
|
||||
* for the corresponding owner, if not already loaded.
|
||||
*/
|
||||
@Override
|
||||
public Owner findById(int id) throws DataAccessException {
|
||||
Owner owner;
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("id", id);
|
||||
owner = this.namedParameterJdbcTemplate.queryForObject(
|
||||
"SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id= :id",
|
||||
params,
|
||||
BeanPropertyRowMapper.newInstance(Owner.class)
|
||||
);
|
||||
} catch (EmptyResultDataAccessException ex) {
|
||||
throw new ObjectRetrievalFailureException(Owner.class, id);
|
||||
}
|
||||
loadPetsAndVisits(owner);
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void loadPetsAndVisits(final Owner owner) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("id", owner.getId());
|
||||
final List<JdbcPet> pets = this.namedParameterJdbcTemplate.query(
|
||||
"SELECT pets.id, name, birth_date, type_id, owner_id, visits.id as visit_id, visit_date, description, pet_id FROM pets LEFT OUTER JOIN visits ON pets.id = pet_id WHERE owner_id=:id",
|
||||
params,
|
||||
new JdbcPetVisitExtractor()
|
||||
);
|
||||
Collection<PetType> petTypes = getPetTypes();
|
||||
for (JdbcPet pet : pets) {
|
||||
pet.setType(EntityUtils.getById(petTypes, PetType.class, pet.getTypeId()));
|
||||
owner.addPet(pet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(Owner owner) throws DataAccessException {
|
||||
BeanPropertySqlParameterSource parameterSource = new BeanPropertySqlParameterSource(owner);
|
||||
if (owner.isNew()) {
|
||||
Number newKey = this.insertOwner.executeAndReturnKey(parameterSource);
|
||||
owner.setId(newKey.intValue());
|
||||
} else {
|
||||
this.namedParameterJdbcTemplate.update(
|
||||
"UPDATE owners SET first_name=:firstName, last_name=:lastName, address=:address, " +
|
||||
"city=:city, telephone=:telephone WHERE id=:id",
|
||||
parameterSource);
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<PetType> getPetTypes() throws DataAccessException {
|
||||
return this.namedParameterJdbcTemplate.query(
|
||||
"SELECT id, name FROM types ORDER BY name", new HashMap<String, Object>(),
|
||||
BeanPropertyRowMapper.newInstance(PetType.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the {@link Pet} and {@link Visit} data for the supplied {@link List} of {@link Owner Owners}.
|
||||
*
|
||||
* @param owners the list of owners for whom the pet and visit data should be loaded
|
||||
* @see #loadPetsAndVisits(Owner)
|
||||
*/
|
||||
private void loadOwnersPetsAndVisits(List<Owner> owners) {
|
||||
for (Owner owner : owners) {
|
||||
loadPetsAndVisits(owner);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* 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.repository.jdbc;
|
||||
|
||||
import org.springframework.samples.petclinic.model.Pet;
|
||||
|
||||
/**
|
||||
* Subclass of Pet that carries temporary id properties which are only relevant for a JDBC implementation of the
|
||||
* PetRepository.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
class JdbcPet extends Pet {
|
||||
|
||||
private int typeId;
|
||||
|
||||
private int ownerId;
|
||||
|
||||
public int getTypeId() {
|
||||
return this.typeId;
|
||||
}
|
||||
|
||||
public void setTypeId(int typeId) {
|
||||
this.typeId = typeId;
|
||||
}
|
||||
|
||||
public int getOwnerId() {
|
||||
return this.ownerId;
|
||||
}
|
||||
|
||||
public void setOwnerId(int ownerId) {
|
||||
this.ownerId = ownerId;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,133 +0,0 @@
|
|||
/*
|
||||
* 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.repository.jdbc;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
|
||||
import org.springframework.orm.ObjectRetrievalFailureException;
|
||||
import org.springframework.samples.petclinic.model.Owner;
|
||||
import org.springframework.samples.petclinic.model.Pet;
|
||||
import org.springframework.samples.petclinic.model.PetType;
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||
import org.springframework.samples.petclinic.repository.PetRepository;
|
||||
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||
import org.springframework.samples.petclinic.util.EntityUtils;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Rob Harrop
|
||||
* @author Sam Brannen
|
||||
* @author Thomas Risberg
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@Repository
|
||||
public class JdbcPetRepositoryImpl implements PetRepository {
|
||||
|
||||
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
||||
|
||||
private SimpleJdbcInsert insertPet;
|
||||
|
||||
private OwnerRepository ownerRepository;
|
||||
|
||||
private VisitRepository visitRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
public JdbcPetRepositoryImpl(DataSource dataSource, OwnerRepository ownerRepository, VisitRepository visitRepository) {
|
||||
this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
|
||||
|
||||
this.insertPet = new SimpleJdbcInsert(dataSource)
|
||||
.withTableName("pets")
|
||||
.usingGeneratedKeyColumns("id");
|
||||
|
||||
this.ownerRepository = ownerRepository;
|
||||
this.visitRepository = visitRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PetType> findPetTypes() throws DataAccessException {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
return this.namedParameterJdbcTemplate.query(
|
||||
"SELECT id, name FROM types ORDER BY name",
|
||||
params,
|
||||
BeanPropertyRowMapper.newInstance(PetType.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pet findById(int id) throws DataAccessException {
|
||||
JdbcPet pet;
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("id", id);
|
||||
pet = this.namedParameterJdbcTemplate.queryForObject(
|
||||
"SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id",
|
||||
params,
|
||||
new JdbcPetRowMapper());
|
||||
} catch (EmptyResultDataAccessException ex) {
|
||||
throw new ObjectRetrievalFailureException(Pet.class, id);
|
||||
}
|
||||
Owner owner = this.ownerRepository.findById(pet.getOwnerId());
|
||||
owner.addPet(pet);
|
||||
pet.setType(EntityUtils.getById(findPetTypes(), PetType.class, pet.getTypeId()));
|
||||
|
||||
List<Visit> visits = this.visitRepository.findByPetId(pet.getId());
|
||||
for (Visit visit : visits) {
|
||||
pet.addVisit(visit);
|
||||
}
|
||||
return pet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(Pet pet) throws DataAccessException {
|
||||
if (pet.isNew()) {
|
||||
Number newKey = this.insertPet.executeAndReturnKey(
|
||||
createPetParameterSource(pet));
|
||||
pet.setId(newKey.intValue());
|
||||
} else {
|
||||
this.namedParameterJdbcTemplate.update(
|
||||
"UPDATE pets SET name=:name, birth_date=:birth_date, type_id=:type_id, " +
|
||||
"owner_id=:owner_id WHERE id=:id",
|
||||
createPetParameterSource(pet));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link MapSqlParameterSource} based on data values from the supplied {@link Pet} instance.
|
||||
*/
|
||||
private MapSqlParameterSource createPetParameterSource(Pet pet) {
|
||||
return new MapSqlParameterSource()
|
||||
.addValue("id", pet.getId())
|
||||
.addValue("name", pet.getName())
|
||||
.addValue("birth_date", pet.getBirthDate().toDate())
|
||||
.addValue("type_id", pet.getType().getId())
|
||||
.addValue("owner_id", pet.getOwner().getId());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
* 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.repository.jdbc;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
/**
|
||||
* {@link RowMapper} implementation mapping data from a {@link ResultSet} to the corresponding properties
|
||||
* of the {@link JdbcPet} class.
|
||||
*/
|
||||
class JdbcPetRowMapper implements RowMapper<JdbcPet> {
|
||||
|
||||
@Override
|
||||
public JdbcPet mapRow(ResultSet rs, int rownum) throws SQLException {
|
||||
JdbcPet pet = new JdbcPet();
|
||||
pet.setId(rs.getInt("pets.id"));
|
||||
pet.setName(rs.getString("name"));
|
||||
Date birthDate = rs.getDate("birth_date");
|
||||
pet.setBirthDate(new LocalDate(birthDate));
|
||||
pet.setTypeId(rs.getInt("type_id"));
|
||||
pet.setOwnerId(rs.getInt("owner_id"));
|
||||
return pet;
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2015 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.repository.jdbc;
|
||||
|
||||
import org.springframework.data.jdbc.core.OneToManyResultSetExtractor;
|
||||
import org.springframework.jdbc.core.ResultSetExtractor;
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* {@link ResultSetExtractor} implementation by using the
|
||||
* {@link OneToManyResultSetExtractor} of Spring Data Core JDBC Extensions.
|
||||
*/
|
||||
public class JdbcPetVisitExtractor extends
|
||||
OneToManyResultSetExtractor<JdbcPet, Visit, Integer> {
|
||||
|
||||
public JdbcPetVisitExtractor() {
|
||||
super(new JdbcPetRowMapper(), new JdbcVisitRowMapper());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Integer mapPrimaryKey(ResultSet rs) throws SQLException {
|
||||
return rs.getInt("pets.id");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Integer mapForeignKey(ResultSet rs) throws SQLException {
|
||||
if (rs.getObject("visits.pet_id") == null) {
|
||||
return null;
|
||||
} else {
|
||||
return rs.getInt("visits.pet_id");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addChild(JdbcPet root, Visit child) {
|
||||
root.addVisit(child);
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* 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.repository.jdbc;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.samples.petclinic.model.Specialty;
|
||||
import org.springframework.samples.petclinic.model.Vet;
|
||||
import org.springframework.samples.petclinic.repository.VetRepository;
|
||||
import org.springframework.samples.petclinic.util.EntityUtils;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* A simple JDBC-based implementation of the {@link VetRepository} interface.
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Rob Harrop
|
||||
* @author Sam Brannen
|
||||
* @author Thomas Risberg
|
||||
* @author Mark Fisher
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
@Repository
|
||||
public class JdbcVetRepositoryImpl implements VetRepository {
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
public JdbcVetRepositoryImpl(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the cache of Vets that the ClinicService is holding.
|
||||
*/
|
||||
@Override
|
||||
public Collection<Vet> findAll() throws DataAccessException {
|
||||
List<Vet> vets = new ArrayList<>();
|
||||
// Retrieve the list of all vets.
|
||||
vets.addAll(this.jdbcTemplate.query(
|
||||
"SELECT id, first_name, last_name FROM vets ORDER BY last_name,first_name",
|
||||
BeanPropertyRowMapper.newInstance(Vet.class)));
|
||||
|
||||
// Retrieve the list of all possible specialties.
|
||||
final List<Specialty> specialties = this.jdbcTemplate.query(
|
||||
"SELECT id, name FROM specialties",
|
||||
BeanPropertyRowMapper.newInstance(Specialty.class));
|
||||
|
||||
// Build each vet's list of specialties.
|
||||
for (Vet vet : vets) {
|
||||
final List<Integer> vetSpecialtiesIds = this.jdbcTemplate.query(
|
||||
"SELECT specialty_id FROM vet_specialties WHERE vet_id=?",
|
||||
new BeanPropertyRowMapper<Integer>() {
|
||||
@Override
|
||||
public Integer mapRow(ResultSet rs, int row) throws SQLException {
|
||||
return rs.getInt(1);
|
||||
}
|
||||
},
|
||||
vet.getId());
|
||||
for (int specialtyId : vetSpecialtiesIds) {
|
||||
Specialty specialty = EntityUtils.getById(specialties, Specialty.class, specialtyId);
|
||||
vet.addSpecialty(specialty);
|
||||
}
|
||||
}
|
||||
return vets;
|
||||
}
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
/*
|
||||
* 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.repository.jdbc;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A simple JDBC-based implementation of the {@link VisitRepository} interface.
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Rob Harrop
|
||||
* @author Sam Brannen
|
||||
* @author Thomas Risberg
|
||||
* @author Mark Fisher
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
@Repository
|
||||
public class JdbcVisitRepositoryImpl implements VisitRepository {
|
||||
|
||||
private NamedParameterJdbcTemplate jdbcTemplate;
|
||||
|
||||
private SimpleJdbcInsert insertVisit;
|
||||
|
||||
@Autowired
|
||||
public JdbcVisitRepositoryImpl(DataSource dataSource) {
|
||||
this.jdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
|
||||
|
||||
this.insertVisit = new SimpleJdbcInsert(dataSource)
|
||||
.withTableName("visits")
|
||||
.usingGeneratedKeyColumns("id");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void save(Visit visit) throws DataAccessException {
|
||||
if (visit.isNew()) {
|
||||
Number newKey = this.insertVisit.executeAndReturnKey(
|
||||
createVisitParameterSource(visit));
|
||||
visit.setId(newKey.intValue());
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Visit update not supported");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a {@link MapSqlParameterSource} based on data values from the supplied {@link Visit} instance.
|
||||
*/
|
||||
private MapSqlParameterSource createVisitParameterSource(Visit visit) {
|
||||
return new MapSqlParameterSource()
|
||||
.addValue("id", visit.getId())
|
||||
.addValue("visit_date", visit.getDate().toDate())
|
||||
.addValue("description", visit.getDescription())
|
||||
.addValue("pet_id", visit.getPet().getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Visit> findByPetId(Integer petId) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("id", petId);
|
||||
JdbcPet pet = this.jdbcTemplate.queryForObject(
|
||||
"SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id",
|
||||
params,
|
||||
new JdbcPetRowMapper());
|
||||
|
||||
List<Visit> visits = this.jdbcTemplate.query(
|
||||
"SELECT id as visit_id, visit_date, description FROM visits WHERE pet_id=:id",
|
||||
params, new JdbcVisitRowMapper());
|
||||
|
||||
for (Visit visit: visits) {
|
||||
visit.setPet(pet);
|
||||
}
|
||||
|
||||
return visits;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2015 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.repository.jdbc;
|
||||
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* {@link RowMapper} implementation mapping data from a {@link ResultSet} to the corresponding properties
|
||||
* of the {@link Visit} class.
|
||||
*/
|
||||
class JdbcVisitRowMapper implements RowMapper<Visit> {
|
||||
|
||||
@Override
|
||||
public Visit mapRow(ResultSet rs, int row) throws SQLException {
|
||||
Visit visit = new Visit();
|
||||
visit.setId(rs.getInt("visit_id"));
|
||||
Date visitDate = rs.getDate("visit_date");
|
||||
visit.setDate(new LocalDate(visitDate));
|
||||
visit.setDescription(rs.getString("description"));
|
||||
return visit;
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
/**
|
||||
* The classes in this package represent the JDBC implementation
|
||||
* of PetClinic's persistence layer.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.jdbc;
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* 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.repository.jpa;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.springframework.orm.hibernate3.support.OpenSessionInViewFilter;
|
||||
import org.springframework.samples.petclinic.model.Owner;
|
||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* JPA implementation of the {@link OwnerRepository} interface.
|
||||
*
|
||||
* @author Mike Keith
|
||||
* @author Rod Johnson
|
||||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
* @since 22.4.2006
|
||||
*/
|
||||
@Repository
|
||||
public class JpaOwnerRepositoryImpl implements OwnerRepository {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
|
||||
/**
|
||||
* Important: in the current version of this method, we load Owners with all their Pets and Visits while
|
||||
* we do not need Visits at all and we only need one property from the Pet objects (the 'name' property).
|
||||
* There are some ways to improve it such as:
|
||||
* - creating a Ligtweight class (example here: https://community.jboss.org/wiki/LightweightClass)
|
||||
* - Turning on lazy-loading and using {@link OpenSessionInViewFilter}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Collection<Owner> findByLastName(String lastName) {
|
||||
// using 'join fetch' because a single query should load both owners and pets
|
||||
// using 'left join fetch' because it might happen that an owner does not have pets yet
|
||||
Query query = this.em.createQuery("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName");
|
||||
query.setParameter("lastName", lastName + "%");
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Owner findById(int id) {
|
||||
// using 'join fetch' because a single query should load both owners and pets
|
||||
// using 'left join fetch' because it might happen that an owner does not have pets yet
|
||||
Query query = this.em.createQuery("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id");
|
||||
query.setParameter("id", id);
|
||||
return (Owner) query.getSingleResult();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void save(Owner owner) {
|
||||
if (owner.getId() == null) {
|
||||
this.em.persist(owner);
|
||||
} else {
|
||||
this.em.merge(owner);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* 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.repository.jpa;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import org.springframework.samples.petclinic.model.Pet;
|
||||
import org.springframework.samples.petclinic.model.PetType;
|
||||
import org.springframework.samples.petclinic.repository.PetRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* JPA implementation of the {@link PetRepository} interface.
|
||||
*
|
||||
* @author Mike Keith
|
||||
* @author Rod Johnson
|
||||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
* @since 22.4.2006
|
||||
*/
|
||||
@Repository
|
||||
public class JpaPetRepositoryImpl implements PetRepository {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<PetType> findPetTypes() {
|
||||
return this.em.createQuery("SELECT ptype FROM PetType ptype ORDER BY ptype.name").getResultList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pet findById(int id) {
|
||||
return this.em.find(Pet.class, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(Pet pet) {
|
||||
if (pet.getId() == null) {
|
||||
this.em.persist(pet);
|
||||
} else {
|
||||
this.em.merge(pet);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* 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.repository.jpa;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.samples.petclinic.model.Vet;
|
||||
import org.springframework.samples.petclinic.repository.VetRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* JPA implementation of the {@link VetRepository} interface.
|
||||
*
|
||||
* @author Mike Keith
|
||||
* @author Rod Johnson
|
||||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
* @since 22.4.2006
|
||||
*/
|
||||
@Repository
|
||||
public class JpaVetRepositoryImpl implements VetRepository {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "vets")
|
||||
@SuppressWarnings("unchecked")
|
||||
public Collection<Vet> findAll() {
|
||||
return this.em.createQuery("SELECT distinct vet FROM Vet vet left join fetch vet.specialties ORDER BY vet.lastName, vet.firstName").getResultList();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* 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.repository.jpa;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* JPA implementation of the ClinicService interface using EntityManager.
|
||||
* <p/>
|
||||
* <p>The mappings are defined in "orm.xml" located in the META-INF directory.
|
||||
*
|
||||
* @author Mike Keith
|
||||
* @author Rod Johnson
|
||||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
* @since 22.4.2006
|
||||
*/
|
||||
@Repository
|
||||
public class JpaVisitRepositoryImpl implements VisitRepository {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
|
||||
@Override
|
||||
public void save(Visit visit) {
|
||||
if (visit.getId() == null) {
|
||||
this.em.persist(visit);
|
||||
} else {
|
||||
this.em.merge(visit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Visit> findByPetId(Integer petId) {
|
||||
Query query = this.em.createQuery("SELECT v FROM Visit v where v.pet.id= :id");
|
||||
query.setParameter("id", petId);
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
/**
|
||||
* The classes in this package represent the JPA implementation
|
||||
* of PetClinic's persistence layer.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.jpa;
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* 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.repository.springdatajpa;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.samples.petclinic.model.Owner;
|
||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||
|
||||
/**
|
||||
* Spring Data JPA specialization of the {@link OwnerRepository} interface
|
||||
*
|
||||
* @author Michael Isvy
|
||||
* @since 15.1.2013
|
||||
*/
|
||||
public interface SpringDataOwnerRepository extends OwnerRepository, Repository<Owner, Integer> {
|
||||
|
||||
@Override
|
||||
@Query("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName%")
|
||||
public Collection<Owner> findByLastName(@Param("lastName") String lastName);
|
||||
|
||||
@Override
|
||||
@Query("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id")
|
||||
public Owner findById(@Param("id") int id);
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* 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.repository.springdatajpa;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.samples.petclinic.model.Pet;
|
||||
import org.springframework.samples.petclinic.model.PetType;
|
||||
import org.springframework.samples.petclinic.repository.PetRepository;
|
||||
|
||||
/**
|
||||
* Spring Data JPA specialization of the {@link PetRepository} interface
|
||||
*
|
||||
* @author Michael Isvy
|
||||
* @since 15.1.2013
|
||||
*/
|
||||
public interface SpringDataPetRepository extends PetRepository, Repository<Pet, Integer> {
|
||||
|
||||
@Override
|
||||
@Query("SELECT ptype FROM PetType ptype ORDER BY ptype.name")
|
||||
List<PetType> findPetTypes() throws DataAccessException;
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* 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.repository.springdatajpa;
|
||||
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||
|
||||
/**
|
||||
* Spring Data JPA specialization of the {@link VisitRepository} interface
|
||||
*
|
||||
* @author Michael Isvy
|
||||
* @since 15.1.2013
|
||||
*/
|
||||
public interface SpringDataVisitRepository extends VisitRepository, Repository<Visit, Integer> {
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
/*
|
||||
* 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.util;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.jmx.export.annotation.ManagedAttribute;
|
||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
/**
|
||||
* Simple aspect that monitors call count and call invocation time. It uses JMX annotations and therefore can be
|
||||
* monitored using any JMX console such as the jConsole
|
||||
* <p/>
|
||||
* This is only useful if you use JPA or JDBC. Spring-data-jpa doesn't have any correctly annotated classes to join on
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
* @author Michael Isvy
|
||||
* @since 2.5
|
||||
*/
|
||||
@ManagedResource("petclinic:type=CallMonitor")
|
||||
@Aspect
|
||||
public class CallMonitoringAspect {
|
||||
|
||||
private boolean enabled = true;
|
||||
|
||||
private int callCount = 0;
|
||||
|
||||
private long accumulatedCallTime = 0;
|
||||
|
||||
@ManagedAttribute
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@ManagedAttribute
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@ManagedOperation
|
||||
public void reset() {
|
||||
this.callCount = 0;
|
||||
this.accumulatedCallTime = 0;
|
||||
}
|
||||
|
||||
@ManagedAttribute
|
||||
public int getCallCount() {
|
||||
return callCount;
|
||||
}
|
||||
|
||||
@ManagedAttribute
|
||||
public long getCallTime() {
|
||||
if (this.callCount > 0)
|
||||
return this.accumulatedCallTime / this.callCount;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Around("within(@org.springframework.stereotype.Repository *)")
|
||||
public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
if (this.enabled) {
|
||||
StopWatch sw = new StopWatch(joinPoint.toShortString());
|
||||
|
||||
sw.start("invoke");
|
||||
try {
|
||||
return joinPoint.proceed();
|
||||
} finally {
|
||||
sw.stop();
|
||||
synchronized (this) {
|
||||
this.callCount++;
|
||||
this.accumulatedCallTime += sw.getTotalTimeMillis();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
|
@ -13,17 +13,23 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.springdatajpa;
|
||||
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.samples.petclinic.model.Vet;
|
||||
import org.springframework.samples.petclinic.repository.VetRepository;
|
||||
package org.springframework.samples.petclinic.web;
|
||||
|
||||
/**
|
||||
* Spring Data JPA specialization of the {@link VetRepository} interface
|
||||
*
|
||||
* @author Michael Isvy
|
||||
* @since 15.1.2013
|
||||
*/
|
||||
public interface SpringDataVetRepository extends VetRepository, Repository<Vet, Integer> {
|
||||
import org.springframework.boot.autoconfigure.web.ErrorController;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@Controller
|
||||
public class CustomErrorController implements ErrorController {
|
||||
|
||||
@RequestMapping(value = "/error")
|
||||
public String error() {
|
||||
return "exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrorPath() {
|
||||
return "/error";
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.format.Formatter;
|
||||
import org.springframework.samples.petclinic.model.PetType;
|
||||
import org.springframework.samples.petclinic.service.ClinicService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Instructs Spring MVC on how to parse and print elements of type 'PetType'. Starting from Spring 3.0, Formatters have
|
||||
|
@ -37,6 +38,7 @@ import org.springframework.samples.petclinic.service.ClinicService;
|
|||
* @author Juergen Hoeller
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
@Component
|
||||
public class PetTypeFormatter implements Formatter<PetType> {
|
||||
|
||||
private final ClinicService clinicService;
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package org.springframework.samples.petclinic.web;
|
||||
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@Controller
|
||||
public class WelcomeController {
|
||||
|
||||
@RequestMapping("/")
|
||||
public String welcome() {
|
||||
return "welcome";
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
<html>
|
||||
<body>
|
||||
<p>
|
||||
The Spring Data Binding framework, an internal library used by Spring Web Flow.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
|
@ -1,53 +0,0 @@
|
|||
<head>
|
||||
<style type="text/css">
|
||||
table.speakersTable {
|
||||
width: 70%;
|
||||
padding: 10;
|
||||
spacing: 10;
|
||||
}
|
||||
|
||||
img.speakerPic {
|
||||
float: right;
|
||||
padding: 10;
|
||||
width: 90;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<h1>Organisation</h1>
|
||||
|
||||
<h1>Speakers</h1>
|
||||
<table class="speakersTable">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<img class="speakerPic" alt="Sergiu Bodiu"
|
||||
src="http://m.c.lnkd.licdn.com/mpr/mpr/shrink_200_200/p/4/000/16a/2ba/0ba653e.jpg"/>
|
||||
|
||||
<h2>Sergiu Bodiu </h2>
|
||||
|
||||
<h3> Java Consultant at Bank of America </h3>
|
||||
<font size="5">S</font>easoned consultant experienced in large-scale e-commerce projects, passionate about
|
||||
providing innovative technology solutions to solve complex business problems, have extensive knowledge and
|
||||
experience delivering enterprise wide applications. He is skilled in software design, data modeling,
|
||||
stakeholder management, IT strategic planning, technical know-how and security. Able to design, implement,
|
||||
test and maintain software product components with strong focus on design elegance and software reuse.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<img alt="Sergiu Bodiu" src="http://m.c.lnkd.licdn.com/mpr/mpr/shrink_200_200/p/4/000/16a/2ba/0ba653e.jpg"
|
||||
width="84" height="84" align="right" hspace="10"/>
|
||||
|
||||
<h2>Sergiu Bodiu </h2>
|
||||
|
||||
<h3> Java Consultant at Bank of America </h3>
|
||||
<font size="5">S</font>easoned consultant experienced in large-scale e-commerce projects, passionate about
|
||||
providing innovative technology solutions to solve complex business problems, have extensive knowledge and
|
||||
experience delivering enterprise wide applications. He is skilled in software design, data modeling,
|
||||
stakeholder management, IT strategic planning, technical know-how and security. Able to design, implement,
|
||||
test and maintain software product components with strong focus on design elegance and software reuse.
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
23
src/main/resources/application.properties
Normal file
23
src/main/resources/application.properties
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Web
|
||||
spring.mvc.view.prefix: /WEB-INF/jsp/
|
||||
spring.mvc.view.suffix: .jsp
|
||||
|
||||
|
||||
# JPA
|
||||
spring.jpa.hibernate.ddl-auto: none
|
||||
#spring.jpa.database: HSQL
|
||||
#spring.jpa.show-sql: true
|
||||
#spring.datasource.driverClassName=org.hsqldb.jdbcDriver
|
||||
spring.datasource.schema: classpath*:db/hsqldb/initDB.sql
|
||||
spring.datasource.data: classpath*:db/hsqldb/populateDB.sql
|
||||
#spring.datasource.username: sa
|
||||
#spring.datasource.password:
|
||||
|
||||
# Internationalization
|
||||
spring.messages.basename: messages/messages
|
||||
|
||||
# Actuator / Management
|
||||
management.contextPath: /manage
|
||||
|
||||
# Logging
|
||||
logging.level.org.springframework=INFO
|
15
src/main/resources/banner.txt
Normal file
15
src/main/resources/banner.txt
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
|
||||
|\ _,,,--,,_
|
||||
/,`.-'`' ._ \-;;,_
|
||||
_______ __|,4- ) )_ .;.(__`'-'__ ___ __ _ ___ _______
|
||||
| | '---''(_/._)-'(_\_) | | | | | | | | |
|
||||
| _ | ___|_ _| | | | | |_| | | | __ _ _
|
||||
| |_| | |___ | | | | | | | | | | \ \ \ \
|
||||
| ___| ___| | | | _| |___| | _ | | _| \ \ \ \
|
||||
| | | |___ | | | |_| | | | | | | |_ ) ) ) )
|
||||
|___| |_______| |___| |_______|_______|___|_| |__|___|_______| / / / /
|
||||
==================================================================/_/_/_/
|
||||
|
||||
:: Built with Spring Boot :: ${spring-boot.version}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE xml>
|
||||
|
||||
<configuration scan="true" scanPeriod="30 seconds">
|
||||
|
||||
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
|
||||
<resetJUL>true</resetJUL>
|
||||
</contextListener>
|
||||
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%-5level %logger{0} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!--<logger name="org.hibernate" level="debug"/> -->
|
||||
<logger name="org.springframework.samples.petclinic" level="debug"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -1,96 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Repository and Service layers
|
||||
-->
|
||||
<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" xmlns="http://www.springframework.org/schema/beans"
|
||||
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>
|
|
@ -1,34 +0,0 @@
|
|||
# Properties file with JDBC and JPA settings.
|
||||
#
|
||||
# Applied by <context:property-placeholder location="jdbc.properties"/> from
|
||||
# various application context XML files (e.g., "applicationContext-*.xml").
|
||||
# Targeted at system administrators, to avoid touching the context XML files.
|
||||
|
||||
# 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
|
||||
|
||||
jpa.showSql=true
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# HSQL Settings
|
||||
|
||||
jdbc.driverClassName=org.hsqldb.jdbcDriver
|
||||
jdbc.url=jdbc:hsqldb:mem:petclinic
|
||||
jdbc.username=sa
|
||||
jdbc.password=
|
||||
|
||||
# Property that determines which database to use with an AbstractJpaVendorAdapter
|
||||
jpa.database=HSQL
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# MySQL Settings
|
||||
|
||||
#jdbc.driverClassName=com.mysql.jdbc.Driver
|
||||
#jdbc.url=jdbc:mysql://localhost:3306/petclinic?useUnicode=true&characterEncoding=UTF-8
|
||||
#jdbc.username=root
|
||||
#jdbc.password=petclinic
|
||||
|
||||
# Property that determines which database to use with an AbstractJpaVendorAdapter
|
||||
#jpa.database=MYSQL
|
|
@ -1,43 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Application context definition for PetClinic Datasource.
|
||||
-->
|
||||
<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"
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
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,65 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
- DispatcherServlet application context for PetClinic's web tier.
|
||||
-->
|
||||
<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"
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
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 htmlHeader.jsp for more details) -->
|
||||
<mvc:resources mapping="/resources/**" location="/resources/"/>
|
||||
<mvc:resources mapping="/vendors/**" location="/vendors/"/>
|
||||
|
||||
<mvc:view-controller path="/" view-name="welcome"/>
|
||||
|
||||
<!-- serve static resources (*.html, ...) from src/main/webapp/
|
||||
Required when both servlet-mapping is '/' and static resources need to be served -->
|
||||
<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,40 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
- DispatcherServlet application context for PetClinic's web tier.
|
||||
-->
|
||||
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oxm="http://www.springframework.org/schema/oxm"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd
|
||||
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">
|
||||
<!--
|
||||
- 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.
|
||||
-->
|
||||
<mvc:view-resolvers>
|
||||
<mvc:content-negotiation use-not-acceptable="true">
|
||||
<mvc:default-views>
|
||||
<bean class="org.springframework.web.servlet.view.JstlView">
|
||||
<property name="url" value=""/>
|
||||
</bean>
|
||||
</mvc:default-views>
|
||||
</mvc:content-negotiation>
|
||||
|
||||
<!-- Registering BeanNameViewResolver and InternalViewResolver -->
|
||||
<mvc:bean-name/>
|
||||
<mvc:jsp prefix="/WEB-INF/jsp/" suffix=".jsp"/>
|
||||
</mvc:view-resolvers>
|
||||
|
||||
<!-- 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: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"
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
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>
|
|
@ -6,7 +6,7 @@
|
|||
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
|
||||
|
||||
<html lang="en">
|
||||
<jsp:include page="fragments/htmlHeader.jsp"/>
|
||||
<petclinic:htmlHeader />
|
||||
|
||||
<body>
|
||||
<petclinic:bodyHeader menuName="error"/>
|
||||
|
@ -28,7 +28,7 @@
|
|||
<petclinic:pivotal/>
|
||||
</div>
|
||||
</div>
|
||||
<jsp:include page="fragments/footer.jsp"/>
|
||||
<petclinic:footer/>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
<html lang="en">
|
||||
|
||||
<jsp:include page="../fragments/htmlHeader.jsp"/>
|
||||
<petclinic:htmlHeader />
|
||||
|
||||
<body>
|
||||
<petclinic:bodyHeader menuName="owners"/>
|
||||
|
@ -44,7 +44,7 @@
|
|||
<petclinic:pivotal/>
|
||||
</div>
|
||||
</div>
|
||||
<jsp:include page="../fragments/footer.jsp"/>
|
||||
<petclinic:footer />
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
<html lang="en">
|
||||
|
||||
<jsp:include page="../fragments/htmlHeader.jsp"/>
|
||||
<petclinic:htmlHeader />
|
||||
|
||||
<body>
|
||||
<petclinic:bodyHeader menuName="owners"/>
|
||||
|
@ -45,7 +45,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<jsp:include page="../fragments/footer.jsp"/>
|
||||
<petclinic:footer />
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
<html lang="en">
|
||||
|
||||
<jsp:include page="../fragments/htmlHeader.jsp"/>
|
||||
<petclinic:htmlHeader />
|
||||
|
||||
<body>
|
||||
<petclinic:bodyHeader menuName="owners"/>
|
||||
|
@ -109,7 +109,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<jsp:include page="../fragments/footer.jsp"/>
|
||||
<petclinic:footer />
|
||||
|
||||
</body>
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
<html lang="en">
|
||||
|
||||
<jsp:include page="../fragments/htmlHeader.jsp"/>
|
||||
<petclinic:htmlHeader />
|
||||
|
||||
<body>
|
||||
<petclinic:bodyHeader menuName="owners"/>
|
||||
|
@ -44,7 +44,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<jsp:include page="../fragments/footer.jsp"/>
|
||||
<petclinic:footer />
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
<html lang="en">
|
||||
|
||||
<jsp:include page="../fragments/htmlHeader.jsp"/>
|
||||
<petclinic:htmlHeader />
|
||||
<body>
|
||||
<petclinic:bodyHeader menuName="owners"/>
|
||||
|
||||
|
@ -53,7 +53,7 @@
|
|||
<petclinic:pivotal/>
|
||||
</div>
|
||||
</div>
|
||||
<jsp:include page="../fragments/footer.jsp"/>
|
||||
<petclinic:footer />
|
||||
|
||||
<script>
|
||||
$(function () {
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
<html lang="en">
|
||||
|
||||
<jsp:include page="../fragments/htmlHeader.jsp"/>
|
||||
<petclinic:htmlHeader />
|
||||
|
||||
<body>
|
||||
|
||||
|
@ -72,7 +72,7 @@
|
|||
<petclinic:pivotal/>
|
||||
</div>
|
||||
</div>
|
||||
<jsp:include page="../fragments/footer.jsp"/>
|
||||
<petclinic:footer />
|
||||
<script>
|
||||
$(function () {
|
||||
$("#date").datepicker({dateFormat: 'yy/mm/dd'});
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
<html lang="en">
|
||||
|
||||
<jsp:include page="../fragments/htmlHeader.jsp"/>
|
||||
<petclinic:htmlHeader />
|
||||
|
||||
<body>
|
||||
<petclinic:bodyHeader menuName="vets"/>
|
||||
|
@ -44,7 +44,7 @@
|
|||
<petclinic:pivotal/>
|
||||
</div>
|
||||
</div>
|
||||
<jsp:include page="../fragments/footer.jsp"/>
|
||||
<petclinic:footer />
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
<html lang="en">
|
||||
|
||||
<jsp:include page="fragments/htmlHeader.jsp"/>
|
||||
<petclinic:htmlHeader/>
|
||||
|
||||
<body>
|
||||
<petclinic:bodyHeader menuName="home"/>
|
||||
|
@ -26,7 +26,7 @@
|
|||
<petclinic:pivotal/>
|
||||
</div>
|
||||
</div>
|
||||
<jsp:include page="fragments/footer.jsp"/>
|
||||
<petclinic:footer/>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
All Spring config files (including Spring MVC ones) are inside src/main/resource.
|
||||
There are mostly 2 reasons to that:
|
||||
- All Spring config files are grouped into one single place
|
||||
- It is simpler to reference them from inside JUnit tests
|
|
@ -1,5 +1,5 @@
|
|||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core_1_1" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
|
||||
<%@ attribute name="name" required="true" rtexprvalue="true"
|
||||
description="Name of the active menu: home, owners, vets or error" %>
|
||||
|
|
|
@ -1,118 +0,0 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
|
||||
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
|
||||
version="3.0" metadata-complete="true">
|
||||
|
||||
<display-name>Spring PetClinic</display-name>
|
||||
<description>Spring PetClinic sample application</description>
|
||||
|
||||
<!-- When using Spring jpa, use the following: -->
|
||||
<context-param>
|
||||
<param-name>spring.profiles.active</param-name>
|
||||
<param-value>jpa</param-value>
|
||||
</context-param>
|
||||
|
||||
<!-- When using Spring JDBC, use the following: -->
|
||||
<!-- <context-param>
|
||||
<param-name>spring.profiles.active</param-name>
|
||||
<param-value>jdbc</param-value>
|
||||
</context-param> -->
|
||||
|
||||
<!-- the CallMonitoringAspect counts invocations on classes with @Repository on them. Classes in spring-data-jpa don't have that annotation -->
|
||||
<!-- When using Spring Data JPA, uncomment the following: -->
|
||||
<!--
|
||||
<context-param>
|
||||
<param-name>spring.profiles.active</param-name>
|
||||
<param-value>spring-data-jpa</param-value>
|
||||
</context-param>
|
||||
-->
|
||||
|
||||
<!--
|
||||
- Location of the XML file 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>
|
||||
|
||||
<listener>
|
||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<!--
|
||||
- Servlet that dispatches request to registered handlers (Controller implementations).
|
||||
-->
|
||||
<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>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>petclinic</servlet-name>
|
||||
<url-pattern>/</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<!-- Dandelion servlet definition and mapping -->
|
||||
<servlet>
|
||||
<servlet-name>dandelionServlet</servlet-name>
|
||||
<servlet-class>com.github.dandelion.core.web.DandelionServlet</servlet-class>
|
||||
<load-on-startup>2</load-on-startup>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>dandelionServlet</servlet-name>
|
||||
<url-pattern>/dandelion-assets/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<!-- used to provide the ability to enter Chinese characters inside the Owner Form -->
|
||||
<filter>
|
||||
<filter-name>encodingFilter</filter-name>
|
||||
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
|
||||
<init-param>
|
||||
<param-name>encoding</param-name>
|
||||
<param-value>UTF-8</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>forceEncoding</param-name>
|
||||
<param-value>true</param-value>
|
||||
</init-param>
|
||||
</filter>
|
||||
|
||||
<filter-mapping>
|
||||
<filter-name>encodingFilter</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
|
||||
<!-- Dandelion filter definition and mapping -->
|
||||
<filter>
|
||||
<filter-name>dandelionFilter</filter-name>
|
||||
<filter-class>com.github.dandelion.core.web.DandelionFilter</filter-class>
|
||||
</filter>
|
||||
<filter-mapping>
|
||||
<filter-name>dandelionFilter</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
|
||||
<!-- Dandelion-Datatables filter, used for basic export -->
|
||||
<filter>
|
||||
<filter-name>datatables</filter-name>
|
||||
<filter-class>com.github.dandelion.datatables.core.web.filter.DatatablesFilter</filter-class>
|
||||
</filter>
|
||||
<filter-mapping>
|
||||
<filter-name>datatables</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
|
||||
<!-- No need for welcome-file declaration here.
|
||||
See inside spring/mvc-core-config.xml :
|
||||
<mvc:view-controller path="/" view-name="welcome" />
|
||||
-->
|
||||
|
||||
</web-app>
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* 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.service;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* <p> Integration test using the jdbc profile.
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
* @author Michael Isvy
|
||||
* @see AbstractClinicServiceTests AbstractClinicServiceTests for more details. </p>
|
||||
*/
|
||||
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ActiveProfiles("jdbc")
|
||||
public class ClinicServiceJdbcTests extends AbstractClinicServiceTests {
|
||||
|
||||
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package org.springframework.samples.petclinic.service;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* <p> Integration test using the jpa profile.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
* @see AbstractClinicServiceTests AbstractClinicServiceTests for more details. </p>
|
||||
*/
|
||||
|
||||
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ActiveProfiles("jpa")
|
||||
public class ClinicServiceJpaTests extends AbstractClinicServiceTests {
|
||||
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package org.springframework.samples.petclinic.service;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.samples.petclinic.PetClinicApplication;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
@ -12,9 +14,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||
* @see AbstractClinicServiceTests AbstractClinicServiceTests for more details. </p>
|
||||
*/
|
||||
|
||||
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ActiveProfiles("spring-data-jpa")
|
||||
@SpringApplicationConfiguration(classes = PetClinicApplication.class)
|
||||
public class ClinicServiceSpringDataJpaTests extends AbstractClinicServiceTests {
|
||||
|
||||
}
|
||||
|
|
|
@ -1,44 +1,43 @@
|
|||
package org.springframework.samples.petclinic.web;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.samples.petclinic.PetClinicApplication;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
/**
|
||||
* Test class for {@link CrashController}
|
||||
*
|
||||
* @author Colin But
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration({"classpath:spring/business-config.xml", "classpath:spring/tools-config.xml", "classpath:spring/mvc-core-config.xml"})
|
||||
@SpringApplicationConfiguration(classes = PetClinicApplication.class)
|
||||
@WebAppConfiguration
|
||||
@ActiveProfiles("spring-data-jpa")
|
||||
// Waiting https://github.com/spring-projects/spring-boot/issues/5574
|
||||
@Ignore
|
||||
public class CrashControllerTests {
|
||||
|
||||
@Autowired
|
||||
private CrashController crashController;
|
||||
|
||||
@Autowired
|
||||
private SimpleMappingExceptionResolver simpleMappingExceptionResolver;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.mockMvc = MockMvcBuilders
|
||||
.standaloneSetup(crashController)
|
||||
.setHandlerExceptionResolvers(simpleMappingExceptionResolver)
|
||||
//.setHandlerExceptionResolvers(new SimpleMappingExceptionResolver())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.samples.petclinic.PetClinicApplication;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
@ -13,12 +13,9 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|||
|
||||
import static org.hamcrest.Matchers.hasProperty;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
/**
|
||||
* Test class for {@link OwnerController}
|
||||
|
@ -26,9 +23,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||
* @author Colin But
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration({"classpath:spring/business-config.xml", "classpath:spring/tools-config.xml", "classpath:spring/mvc-core-config.xml"})
|
||||
@SpringApplicationConfiguration(classes = PetClinicApplication.class)
|
||||
@WebAppConfiguration
|
||||
@ActiveProfiles("spring-data-jpa")
|
||||
public class OwnerControllerTests {
|
||||
|
||||
private static final int TEST_OWNER_ID = 1;
|
||||
|
|
|
@ -10,7 +10,10 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||
import org.springframework.format.support.FormattingConversionServiceFactoryBean;
|
||||
import org.springframework.samples.petclinic.PetClinicApplication;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
@ -24,9 +27,8 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|||
* @author Colin But
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration({"classpath:spring/business-config.xml", "classpath:spring/tools-config.xml", "classpath:spring/mvc-core-config.xml"})
|
||||
@SpringApplicationConfiguration(classes = PetClinicApplication.class)
|
||||
@WebAppConfiguration
|
||||
@ActiveProfiles("spring-data-jpa")
|
||||
public class PetControllerTests {
|
||||
|
||||
private static final int TEST_OWNER_ID = 1;
|
||||
|
@ -36,15 +38,17 @@ public class PetControllerTests {
|
|||
private PetController petController;
|
||||
|
||||
@Autowired
|
||||
private FormattingConversionServiceFactoryBean formattingConversionServiceFactoryBean;
|
||||
private PetTypeFormatter petTypeFormatter;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
DefaultFormattingConversionService formattingConversionService = new DefaultFormattingConversionService();
|
||||
formattingConversionService.addFormatter(petTypeFormatter);
|
||||
this.mockMvc = MockMvcBuilders
|
||||
.standaloneSetup(petController)
|
||||
.setConversionService(formattingConversionServiceFactoryBean.getObject())
|
||||
.setConversionService(formattingConversionService)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,28 +1,27 @@
|
|||
package org.springframework.samples.petclinic.web;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.samples.petclinic.PetClinicApplication;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
/**
|
||||
* Test class for the {@link VetController}
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration({"classpath:spring/business-config.xml", "classpath:spring/tools-config.xml", "classpath:spring/mvc-core-config.xml"})
|
||||
@SpringApplicationConfiguration(classes = PetClinicApplication.class)
|
||||
@WebAppConfiguration
|
||||
@ActiveProfiles("spring-data-jpa")
|
||||
public class VetControllerTests {
|
||||
|
||||
@Autowired
|
||||
|
|
|
@ -4,8 +4,8 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.samples.petclinic.PetClinicApplication;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
@ -13,9 +13,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
/**
|
||||
* Test class for {@link VisitController}
|
||||
|
@ -23,9 +21,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||
* @author Colin But
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration({"classpath:spring/business-config.xml", "classpath:spring/tools-config.xml", "classpath:spring/mvc-core-config.xml"})
|
||||
@SpringApplicationConfiguration(classes = PetClinicApplication.class)
|
||||
@WebAppConfiguration
|
||||
@ActiveProfiles("spring-data-jpa")
|
||||
public class VisitControllerTests {
|
||||
|
||||
private static final int TEST_PET_ID = 1;
|
||||
|
|
Loading…
Reference in a new issue