petclinic-uncached
Changes
pom.xml 169(+53 -116)
src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java 158(+0 -158)
src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImpl.java 133(+0 -133)
src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRowMapper.java 43(+0 -43)
src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetVisitExtractor.java 54(+0 -54)
src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java 89(+0 -89)
src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java 105(+0 -105)
src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java 42(+0 -42)
src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java 81(+0 -81)
src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaPetRepositoryImpl.java 63(+0 -63)
src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVetRepositoryImpl.java 51(+0 -51)
src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImpl.java 64(+0 -64)
src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataOwnerRepository.java 41(+0 -41)
src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataPetRepository.java 38(+0 -38)
src/main/resources/application.properties 23(+23 -0)
src/main/resources/banner.txt 15(+15 -0)
src/main/resources/ehcache.xml 0(+0 -0)
src/main/resources/ehcache.xsd 0(+0 -0)
Details
pom.xml 169(+53 -116)
diff --git a/pom.xml b/pom.xml
index 13040a7..277927b 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>
@@ -223,31 +182,11 @@
<!-- 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,17 +215,15 @@
<!-- 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>
<version>3.0</version>
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 0000000..ec6e017
--- /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 d0158d9..9a09bd7 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 970cdcb..3dec7a3 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/PetClinicApplication.java b/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java
new file mode 100644
index 0000000..c163994
--- /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/repository/OwnerRepository.java b/src/main/java/org/springframework/samples/petclinic/repository/OwnerRepository.java
index a0869d1..841d0bc 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 1770e85..58e73d7 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 923c3c2..aabdfd6 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 96b7a20..e734f32 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/web/PetTypeFormatter.java b/src/main/java/org/springframework/samples/petclinic/web/PetTypeFormatter.java
index 3d47d22..71a060c 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 0000000..efa9c32
--- /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";
+ }
+}
src/main/resources/application.properties 23(+23 -0)
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
new file mode 100644
index 0000000..688ae20
--- /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
src/main/resources/banner.txt 15(+15 -0)
diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt
new file mode 100644
index 0000000..6225d12
--- /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/webapp/WEB-INF/jsp/exception.jsp b/src/main/webapp/WEB-INF/jsp/exception.jsp
index a4fde6c..2193252 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 77826de..d5cf881 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 e9f9b90..e8f61db 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 54eade3..88af6b4 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 1824a28..65e17e1 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 e4f20e9..c098056 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 d1f9017..abcd42e 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 e3cdde2..3d1255e 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 ee99745..23b258f 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/tags/menu.tag b/src/main/webapp/WEB-INF/tags/menu.tag
index 066f75a..933bd05 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/test/java/org/springframework/samples/petclinic/service/ClinicServiceSpringDataJpaTests.java b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceSpringDataJpaTests.java
index 31b6228..d0781b8 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 ee83b8a..41d233e 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 2d85c9d..adafee2 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 8d42c77..a28d06b 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 5446c07..816c4e5 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 a9f9ea0..42a665a 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;