diff --git a/pom.xml b/pom.xml index 13040a7010da01fd53e7bf9ebe5f4ec9fc61af32..277927bfa56870f2593886eaa60cb69e8131a6db 100644 --- a/pom.xml +++ b/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,98 +43,65 @@ </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> + <!-- Spring et Spring Boot 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> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> </dependency> - <dependency> - <groupId>javax.servlet.jsp.jstl</groupId> - <artifactId>javax.servlet.jsp.jstl-api</artifactId> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-cache</artifactId> </dependency> <dependency> - <groupId>org.apache.taglibs</groupId> - <artifactId>taglibs-standard-jstlel</artifactId> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> - <!-- JSon --> <dependency> - <groupId>com.jayway.jsonpath</groupId> - <artifactId>json-path</artifactId> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> - <!-- SPRING, SPRING, SPRINGITY SPRING --> <dependency> <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter</artifactId> + <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-jpa</artifactId> + <groupId>org.springframework</groupId> + <artifactId>spring-context-support</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> + <groupId>org.springframework</groupId> + <artifactId>spring-oxm</artifactId> </dependency> + + + <!-- Tomcat --> <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + <scope>provided</scope> </dependency> <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-webmvc</artifactId> + <groupId>org.apache.tomcat.embed</groupId> + <artifactId>tomcat-embed-jasper</artifactId> + <scope>provided</scope> </dependency> - <!-- used for EhCacheCacheManager --> <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context-support</artifactId> + <groupId>javax.servlet</groupId> + <artifactId>jstl</artifactId> </dependency> + + + <!-- JSon --> <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-oxm</artifactId> + <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> diff --git a/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java b/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..c1639946beea9499ca45c9701101236d043c815e --- /dev/null +++ b/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java @@ -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); + } + +} diff --git a/src/main/java/org/springframework/samples/petclinic/config/CustomViewsConfiguration.java b/src/main/java/org/springframework/samples/petclinic/config/CustomViewsConfiguration.java new file mode 100644 index 0000000000000000000000000000000000000000..9bfdd1cdc839cad1362dcec8ef52df3dbbf23f5e --- /dev/null +++ b/src/main/java/org/springframework/samples/petclinic/config/CustomViewsConfiguration.java @@ -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); + } +} diff --git a/src/main/java/org/springframework/samples/petclinic/config/DandelionConfig.java b/src/main/java/org/springframework/samples/petclinic/config/DandelionConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..ec6e017864091a856826185714462ffbd4acdef9 --- /dev/null +++ b/src/main/java/org/springframework/samples/petclinic/config/DandelionConfig.java @@ -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; + } +} diff --git a/src/main/java/org/springframework/samples/petclinic/model/Owner.java b/src/main/java/org/springframework/samples/petclinic/model/Owner.java index d0158d907a451d417351115ab0e1b886fa485137..9a09bd775163098c8b632388495f172b0b4f7b23 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Owner.java +++ b/src/main/java/org/springframework/samples/petclinic/model/Owner.java @@ -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); } diff --git a/src/main/java/org/springframework/samples/petclinic/model/Pet.java b/src/main/java/org/springframework/samples/petclinic/model/Pet.java index 970cdcb762324d9f5ca1189ae54c45bc9305ea41..3dec7a31021ad98bcbba21bbbdf394c288694068 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Pet.java +++ b/src/main/java/org/springframework/samples/petclinic/model/Pet.java @@ -110,4 +110,8 @@ public class Pet extends NamedEntity { visit.setPet(this); } + + + + } diff --git a/src/main/java/org/springframework/samples/petclinic/repository/OwnerRepository.java b/src/main/java/org/springframework/samples/petclinic/repository/OwnerRepository.java index a0869d1e349c9bab6f32f1edf1080466e071ca5e..841d0bcd8b6b3560a45aefa05e32792d0618d221 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/OwnerRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/OwnerRepository.java @@ -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); } diff --git a/src/main/java/org/springframework/samples/petclinic/repository/PetRepository.java b/src/main/java/org/springframework/samples/petclinic/repository/PetRepository.java index 1770e855503a64a7ff4a24c418ad2b9958eb0fe4..58e73d7f67a3823b922cc6ef387528dbe99d62c2 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/PetRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/PetRepository.java @@ -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); } + diff --git a/src/main/java/org/springframework/samples/petclinic/repository/VetRepository.java b/src/main/java/org/springframework/samples/petclinic/repository/VetRepository.java index 923c3c23df40791f471922259d5789652ce754a4..aabdfd65d9b04c6054a7268802f329b634e7fb46 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/VetRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/VetRepository.java @@ -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. diff --git a/src/main/java/org/springframework/samples/petclinic/repository/VisitRepository.java b/src/main/java/org/springframework/samples/petclinic/repository/VisitRepository.java index 96b7a208c8540326f551849a4be677e462924c24..e734f3275c5c251de07c0c9cc2fdc98117e47db2 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/VisitRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/VisitRepository.java @@ -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. diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java deleted file mode 100644 index 45de1aee0093dfb5ceb6ad9dbc2bca45621b0bcb..0000000000000000000000000000000000000000 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java +++ /dev/null @@ -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); - } - } - - -} diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPet.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPet.java deleted file mode 100644 index 4c266b93172647b43470d82782537fe672455cc8..0000000000000000000000000000000000000000 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPet.java +++ /dev/null @@ -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; - } - -} diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImpl.java deleted file mode 100644 index 885c2bc2ff2d57cd1b190ca21401f448d3d2ea66..0000000000000000000000000000000000000000 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImpl.java +++ /dev/null @@ -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()); - } - -} diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRowMapper.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRowMapper.java deleted file mode 100644 index 6420df1630fe1e81be7a18c1686e5f6db5022e3f..0000000000000000000000000000000000000000 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRowMapper.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetVisitExtractor.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetVisitExtractor.java deleted file mode 100644 index 6a4ba62c3e4c0143ec374c6814eb4905889a253c..0000000000000000000000000000000000000000 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetVisitExtractor.java +++ /dev/null @@ -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); - } -} diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java deleted file mode 100644 index 0231275c1ca4a757b227e7aebe32d89b7676f882..0000000000000000000000000000000000000000 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java deleted file mode 100644 index ecae18d997cd84039d78f152779cb91bd6d79e99..0000000000000000000000000000000000000000 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java +++ /dev/null @@ -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; - } - -} diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java deleted file mode 100644 index edc4527a349566f8b27db923628c4d0cb64a15ba..0000000000000000000000000000000000000000 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/package-info.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/package-info.java deleted file mode 100644 index 376da279fd44f4839e7528fce7359232a69ac9ca..0000000000000000000000000000000000000000 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/package-info.java +++ /dev/null @@ -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; - diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java deleted file mode 100644 index 3972dd349b627e7543d39c77ae233957843ed4bb..0000000000000000000000000000000000000000 --- a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java +++ /dev/null @@ -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); - } - - } - -} diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaPetRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaPetRepositoryImpl.java deleted file mode 100644 index 227140d96c1bd1da23857446a88dfd16ff38d327..0000000000000000000000000000000000000000 --- a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaPetRepositoryImpl.java +++ /dev/null @@ -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); - } - } - -} diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVetRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVetRepositoryImpl.java deleted file mode 100644 index e4c222b65a4f6ea2493a9f50aa252be7f8ce18b3..0000000000000000000000000000000000000000 --- a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVetRepositoryImpl.java +++ /dev/null @@ -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(); - } - -} diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImpl.java deleted file mode 100644 index 16a9b3536f55dcc97802e1d3b15cf5546f50954a..0000000000000000000000000000000000000000 --- a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImpl.java +++ /dev/null @@ -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(); - } - -} diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jpa/package-info.java b/src/main/java/org/springframework/samples/petclinic/repository/jpa/package-info.java deleted file mode 100644 index 087dc15b6630c14887561b1dc325487fceb609e4..0000000000000000000000000000000000000000 --- a/src/main/java/org/springframework/samples/petclinic/repository/jpa/package-info.java +++ /dev/null @@ -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; - diff --git a/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataOwnerRepository.java b/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataOwnerRepository.java deleted file mode 100644 index 24c573eb7d4fe0c0a9ebf50cd8c882b7b46f7a26..0000000000000000000000000000000000000000 --- a/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataOwnerRepository.java +++ /dev/null @@ -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); -} diff --git a/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataPetRepository.java b/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataPetRepository.java deleted file mode 100644 index 56a41314737bc5d9374c996ab927afdc460398b2..0000000000000000000000000000000000000000 --- a/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataPetRepository.java +++ /dev/null @@ -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; -} diff --git a/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataVisitRepository.java b/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataVisitRepository.java deleted file mode 100644 index 84740224b7fa9fe997ab9ee5f24938f8f79014e8..0000000000000000000000000000000000000000 --- a/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataVisitRepository.java +++ /dev/null @@ -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> { -} diff --git a/src/main/java/org/springframework/samples/petclinic/util/CallMonitoringAspect.java b/src/main/java/org/springframework/samples/petclinic/util/CallMonitoringAspect.java deleted file mode 100644 index fddf17dfae2b12d9bfc0a31f6a859a57aba57739..0000000000000000000000000000000000000000 --- a/src/main/java/org/springframework/samples/petclinic/util/CallMonitoringAspect.java +++ /dev/null @@ -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(); - } - } - -} diff --git a/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataVetRepository.java b/src/main/java/org/springframework/samples/petclinic/web/CustomErrorController.java similarity index 51% rename from src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataVetRepository.java rename to src/main/java/org/springframework/samples/petclinic/web/CustomErrorController.java index b8211b707ba95acaf38aa21b481b93b772461cfc..965697c65f03b64f8d95cee18bcc44a25ed69f8b 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataVetRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/web/CustomErrorController.java @@ -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"; + } } diff --git a/src/main/java/org/springframework/samples/petclinic/web/PetTypeFormatter.java b/src/main/java/org/springframework/samples/petclinic/web/PetTypeFormatter.java index 3d47d220179bd4d7962f5c8392db1056d76585a3..71a060ca55ba30785d14aeb96b1d680a36be5895 100644 --- a/src/main/java/org/springframework/samples/petclinic/web/PetTypeFormatter.java +++ b/src/main/java/org/springframework/samples/petclinic/web/PetTypeFormatter.java @@ -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; diff --git a/src/main/java/org/springframework/samples/petclinic/web/WelcomeController.java b/src/main/java/org/springframework/samples/petclinic/web/WelcomeController.java new file mode 100644 index 0000000000000000000000000000000000000000..efa9c3236fe5d59250b222623caf0bc857f0b34c --- /dev/null +++ b/src/main/java/org/springframework/samples/petclinic/web/WelcomeController.java @@ -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"; + } +} diff --git a/src/main/java/overview.html b/src/main/java/overview.html deleted file mode 100644 index df4f4d6b7fb8f9f0a0dc3befe95d923f3019516e..0000000000000000000000000000000000000000 --- a/src/main/java/overview.html +++ /dev/null @@ -1,7 +0,0 @@ -<html> -<body> -<p> - The Spring Data Binding framework, an internal library used by Spring Web Flow. -</p> -</body> -</html> \ No newline at end of file diff --git a/src/main/java/test.html b/src/main/java/test.html deleted file mode 100644 index 8c5cb2cf3e7511536521ec6e8eadd82c198264e0..0000000000000000000000000000000000000000 --- a/src/main/java/test.html +++ /dev/null @@ -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> diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000000000000000000000000000000000000..688ae2044a898a57994204c70e159a35c2cd3ed3 --- /dev/null +++ b/src/main/resources/application.properties @@ -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 diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt new file mode 100644 index 0000000000000000000000000000000000000000..6225d1208c0534e9435db30285427780fab5dace --- /dev/null +++ b/src/main/resources/banner.txt @@ -0,0 +1,15 @@ + + + |\ _,,,--,,_ + /,`.-'`' ._ \-;;,_ + _______ __|,4- ) )_ .;.(__`'-'__ ___ __ _ ___ _______ + | | '---''(_/._)-'(_\_) | | | | | | | | | + | _ | ___|_ _| | | | | |_| | | | __ _ _ + | |_| | |___ | | | | | | | | | | \ \ \ \ + | ___| ___| | | | _| |___| | _ | | _| \ \ \ \ + | | | |___ | | | |_| | | | | | | |_ ) ) ) ) + |___| |_______| |___| |_______|_______|___|_| |__|___|_______| / / / / + ==================================================================/_/_/_/ + +:: Built with Spring Boot :: ${spring-boot.version} + diff --git a/src/main/resources/cache/ehcache.xml b/src/main/resources/ehcache.xml similarity index 100% rename from src/main/resources/cache/ehcache.xml rename to src/main/resources/ehcache.xml diff --git a/src/main/resources/cache/ehcache.xsd b/src/main/resources/ehcache.xsd similarity index 100% rename from src/main/resources/cache/ehcache.xsd rename to src/main/resources/ehcache.xsd diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml deleted file mode 100644 index 54bfd5f2dde840f08267365c1e88803a4d2a48d0..0000000000000000000000000000000000000000 --- a/src/main/resources/logback.xml +++ /dev/null @@ -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> diff --git a/src/main/resources/spring/business-config.xml b/src/main/resources/spring/business-config.xml deleted file mode 100644 index a029c45ab15fdca789e46dada690850c8071310e..0000000000000000000000000000000000000000 --- a/src/main/resources/spring/business-config.xml +++ /dev/null @@ -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> diff --git a/src/main/resources/spring/data-access.properties b/src/main/resources/spring/data-access.properties deleted file mode 100644 index 567f726a4fb196ae1b387343284601a136149903..0000000000000000000000000000000000000000 --- a/src/main/resources/spring/data-access.properties +++ /dev/null @@ -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 diff --git a/src/main/resources/spring/datasource-config.xml b/src/main/resources/spring/datasource-config.xml deleted file mode 100644 index aa705de14d7bf3a29fc9b73e1cd6977cbcafe588..0000000000000000000000000000000000000000 --- a/src/main/resources/spring/datasource-config.xml +++ /dev/null @@ -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> diff --git a/src/main/resources/spring/mvc-core-config.xml b/src/main/resources/spring/mvc-core-config.xml deleted file mode 100644 index 6e254423f263568cac73e7afdbd4ecebe78f0258..0000000000000000000000000000000000000000 --- a/src/main/resources/spring/mvc-core-config.xml +++ /dev/null @@ -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> diff --git a/src/main/resources/spring/mvc-view-config.xml b/src/main/resources/spring/mvc-view-config.xml deleted file mode 100644 index 9ba6723c520c288c919e89db7ce5ffd4cb83f525..0000000000000000000000000000000000000000 --- a/src/main/resources/spring/mvc-view-config.xml +++ /dev/null @@ -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> diff --git a/src/main/resources/spring/tools-config.xml b/src/main/resources/spring/tools-config.xml deleted file mode 100644 index 61db5e57dbd1b249dcfd190bd342b93540c94772..0000000000000000000000000000000000000000 --- a/src/main/resources/spring/tools-config.xml +++ /dev/null @@ -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> diff --git a/src/main/webapp/WEB-INF/jsp/exception.jsp b/src/main/webapp/WEB-INF/jsp/exception.jsp index a4fde6ca36183b1b86b088de20b9e6f6dc8ab707..21932524d3fe900fcdc53c4671f96aa9f21c589f 100644 --- a/src/main/webapp/WEB-INF/jsp/exception.jsp +++ b/src/main/webapp/WEB-INF/jsp/exception.jsp @@ -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> diff --git a/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp b/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp index 77826de8a221f67790b853e974fadd8f33e5a23e..d5cf881f6aaadd29065ac60c7ecaae72a2720f79 100644 --- a/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp @@ -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> diff --git a/src/main/webapp/WEB-INF/jsp/owners/findOwners.jsp b/src/main/webapp/WEB-INF/jsp/owners/findOwners.jsp index e9f9b9061d8afb830c571d92647379b4577b1d86..e8f61dbcd413d0602cb32592f20273025fa4137b 100644 --- a/src/main/webapp/WEB-INF/jsp/owners/findOwners.jsp +++ b/src/main/webapp/WEB-INF/jsp/owners/findOwners.jsp @@ -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> diff --git a/src/main/webapp/WEB-INF/jsp/owners/ownerDetails.jsp b/src/main/webapp/WEB-INF/jsp/owners/ownerDetails.jsp index 54eade30a987c4d3ac7ef5d7c23106139836c0fd..88af6b4d1d1886588de05fa8ddc23ea311d36900 100644 --- a/src/main/webapp/WEB-INF/jsp/owners/ownerDetails.jsp +++ b/src/main/webapp/WEB-INF/jsp/owners/ownerDetails.jsp @@ -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> diff --git a/src/main/webapp/WEB-INF/jsp/owners/ownersList.jsp b/src/main/webapp/WEB-INF/jsp/owners/ownersList.jsp index 1824a288cff20884f31a71bff3e268d8c97db0f0..65e17e1c66ea2324733b1102d98223eeb5328665 100644 --- a/src/main/webapp/WEB-INF/jsp/owners/ownersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/owners/ownersList.jsp @@ -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> diff --git a/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp b/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp index e4f20e9ffa67f6eb8ad853d6e7a6b7adb937ba84..c098056d89dd156ed61a76e093aa82ce109f5b36 100644 --- a/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp @@ -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 () { diff --git a/src/main/webapp/WEB-INF/jsp/pets/createOrUpdateVisitForm.jsp b/src/main/webapp/WEB-INF/jsp/pets/createOrUpdateVisitForm.jsp index d1f90170152f91baa28bdd6a3cb4a2aa3f8f213b..abcd42eae8868c5df81dddfc086b168ee0deb7e6 100644 --- a/src/main/webapp/WEB-INF/jsp/pets/createOrUpdateVisitForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/pets/createOrUpdateVisitForm.jsp @@ -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'}); diff --git a/src/main/webapp/WEB-INF/jsp/vets/vetList.jsp b/src/main/webapp/WEB-INF/jsp/vets/vetList.jsp index e3cdde22c9c52f4209978dc114fa994807fdceea..3d1255e123124db18fe62615317b61204dc0e79f 100644 --- a/src/main/webapp/WEB-INF/jsp/vets/vetList.jsp +++ b/src/main/webapp/WEB-INF/jsp/vets/vetList.jsp @@ -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> diff --git a/src/main/webapp/WEB-INF/jsp/welcome.jsp b/src/main/webapp/WEB-INF/jsp/welcome.jsp index ee9974590a69114fbe1f1db1bf560d2fbb1e1777..23b258f02c029a8e61c32dc23d3a9abc35834767 100644 --- a/src/main/webapp/WEB-INF/jsp/welcome.jsp +++ b/src/main/webapp/WEB-INF/jsp/welcome.jsp @@ -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> diff --git a/src/main/webapp/WEB-INF/no-spring-config-files-there.txt b/src/main/webapp/WEB-INF/no-spring-config-files-there.txt deleted file mode 100644 index 45fb7bf0a6dbcbb738bd21fad0129e0c68770960..0000000000000000000000000000000000000000 --- a/src/main/webapp/WEB-INF/no-spring-config-files-there.txt +++ /dev/null @@ -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 \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/fragments/footer.jsp b/src/main/webapp/WEB-INF/tags/footer.tag similarity index 100% rename from src/main/webapp/WEB-INF/jsp/fragments/footer.jsp rename to src/main/webapp/WEB-INF/tags/footer.tag diff --git a/src/main/webapp/WEB-INF/jsp/fragments/htmlHeader.jsp b/src/main/webapp/WEB-INF/tags/htmlHeader.tag similarity index 100% rename from src/main/webapp/WEB-INF/jsp/fragments/htmlHeader.jsp rename to src/main/webapp/WEB-INF/tags/htmlHeader.tag diff --git a/src/main/webapp/WEB-INF/tags/menu.tag b/src/main/webapp/WEB-INF/tags/menu.tag index 066f75aa57dab3ca742af387f768924b2cc32d9e..933bd0515552d57aff857dcc2355c058fde8cbba 100644 --- a/src/main/webapp/WEB-INF/tags/menu.tag +++ b/src/main/webapp/WEB-INF/tags/menu.tag @@ -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" %> diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index ea965de257a930c0478136f72babfd8707a3bc5a..0000000000000000000000000000000000000000 --- a/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -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> diff --git a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJdbcTests.java b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJdbcTests.java deleted file mode 100644 index 74c5df7cf56cbd3b0124604d9e79dd4eace53524..0000000000000000000000000000000000000000 --- a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJdbcTests.java +++ /dev/null @@ -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 { - - -} diff --git a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJpaTests.java b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJpaTests.java deleted file mode 100644 index dba2b195a0b571c061f251fdcfba6f8577a86c5c..0000000000000000000000000000000000000000 --- a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJpaTests.java +++ /dev/null @@ -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 { - -} diff --git a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceSpringDataJpaTests.java b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceSpringDataJpaTests.java index 31b62289fa16c4ca87394473888808691e41d8d2..d0781b8e32ba8edc6836ae4f53518fcfbab7cbaa 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceSpringDataJpaTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceSpringDataJpaTests.java @@ -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 { } diff --git a/src/test/java/org/springframework/samples/petclinic/web/CrashControllerTests.java b/src/test/java/org/springframework/samples/petclinic/web/CrashControllerTests.java index ee83b8a4dbbc7a8b19d2713c7af0a8e352d721e6..41d233e73b8b9787c7be8a6c13566f399887eb7d 100644 --- a/src/test/java/org/springframework/samples/petclinic/web/CrashControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/web/CrashControllerTests.java @@ -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(); } diff --git a/src/test/java/org/springframework/samples/petclinic/web/OwnerControllerTests.java b/src/test/java/org/springframework/samples/petclinic/web/OwnerControllerTests.java index 2d85c9d15419ba6698d3db866ee55ba98656ab1e..adafee205a80c2291c787115224939edc530fe11 100644 --- a/src/test/java/org/springframework/samples/petclinic/web/OwnerControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/web/OwnerControllerTests.java @@ -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; diff --git a/src/test/java/org/springframework/samples/petclinic/web/PetControllerTests.java b/src/test/java/org/springframework/samples/petclinic/web/PetControllerTests.java index 8d42c77316ddd1c68119e8cff80d9ed7efd026dd..a28d06b1a27d5171086e6c5ad8558bc899329b0e 100644 --- a/src/test/java/org/springframework/samples/petclinic/web/PetControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/web/PetControllerTests.java @@ -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(); } diff --git a/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java b/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java index 5446c0718e4651342980466709ba93ad2d264abd..816c4e594e1160ca7b4b7ba88ac50eb59f919e85 100644 --- a/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java @@ -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 diff --git a/src/test/java/org/springframework/samples/petclinic/web/VisitControllerTests.java b/src/test/java/org/springframework/samples/petclinic/web/VisitControllerTests.java index a9f9ea0458ea49258de907d8c5111a3aa987cc7f..42a665a38601076007a2216472868a00bc27e2c5 100644 --- a/src/test/java/org/springframework/samples/petclinic/web/VisitControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/web/VisitControllerTests.java @@ -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;