Skip to content
Snippets Groups Projects
Commit e38a9fee authored by Dave Syer's avatar Dave Syer
Browse files

Convert to jar with thymeleaf

parent 3450c3d9
No related branches found
No related tags found
No related merge requests found
Showing
with 274 additions and 418 deletions
This diff is collapsed.
FROM openjdk:alpine
MAINTAINER Antoine Rey <antoine.rey@free.fr>
# Spring Boot application creates working directories for Tomcat by default
VOLUME /tmp
ADD petclinic.war petclinic.war
RUN sh -c 'touch /petclinic.war'
# To reduce Tomcat startup time we added a system property pointing to "/dev/urandom" as a source of entropy.
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/petclinic.war"]
......@@ -18,23 +18,16 @@ package org.springframework.samples.petclinic;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
/**
* PetClinic Spring Boot Application.
*
*/
@SpringBootApplication
public class PetClinicApplication extends SpringBootServletInitializer {
public class PetClinicApplication {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(PetClinicApplication.class);
public static void main(String[] args) throws Exception {
SpringApplication.run(PetClinicApplication.class, args);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(PetClinicApplication.class, args);
}
}
......@@ -34,6 +34,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
......@@ -62,7 +63,7 @@ public class Pet extends NamedEntity {
private Owner owner;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "pet", fetch = FetchType.EAGER)
private Set<Visit> visits;
private Set<Visit> visits = new LinkedHashSet<>();
public void setBirthDate(Date birthDate) {
......
......@@ -17,11 +17,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;
/**
......@@ -51,7 +49,7 @@ public interface OwnerRepository extends Repository<Owner, Integer> {
* @return the {@link Owner} if found
*/
@Query("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id")
Owner findById(@Param("id") int id);
Owner findById(@Param("id") Integer id);
/**
* Save an {@link Owner} to the data store, either inserting or updating it.
......
......@@ -17,10 +17,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;
......@@ -47,7 +45,7 @@ public interface PetRepository extends Repository<Pet, Integer> {
* @param id the id to search for
* @return the {@link Pet} if found
*/
Pet findById(int id);
Pet findById(Integer id);
/**
* Save a {@link Pet} to the data store, either inserting or updating it.
......
......@@ -29,8 +29,8 @@ import javax.cache.annotation.CacheResult;
import java.util.Collection;
/**
* Mostly used as a facade for all Petclinic controllers
* Also a placeholder for @Transactional and @CacheResult annotations
* Mostly used as a facade for all Petclinic controllers Also a placeholder
* for @Transactional and @CacheResult annotations
*
* @author Michael Isvy
*/
......@@ -43,7 +43,8 @@ public class ClinicServiceImpl implements ClinicService {
private VisitRepository visitRepository;
@Autowired
public ClinicServiceImpl(PetRepository petRepository, VetRepository vetRepository, OwnerRepository ownerRepository, VisitRepository visitRepository) {
public ClinicServiceImpl(PetRepository petRepository, VetRepository vetRepository, OwnerRepository ownerRepository,
VisitRepository visitRepository) {
this.petRepository = petRepository;
this.vetRepository = vetRepository;
this.ownerRepository = ownerRepository;
......@@ -74,14 +75,12 @@ public class ClinicServiceImpl implements ClinicService {
ownerRepository.save(owner);
}
@Override
@Transactional
public void saveVisit(Visit visit) throws DataAccessException {
visitRepository.save(visit);
}
@Override
@Transactional(readOnly = true)
public Pet findPetById(int id) throws DataAccessException {
......@@ -101,10 +100,9 @@ public class ClinicServiceImpl implements ClinicService {
return vetRepository.findAll();
}
@Override
public Collection<Visit> findVisitsByPetId(int petId) {
return visitRepository.findByPetId(petId);
}
@Override
public Collection<Visit> findVisitsByPetId(int petId) {
return visitRepository.findByPetId(petId);
}
}
......@@ -23,18 +23,16 @@ import org.springframework.web.bind.annotation.RequestMethod;
* Controller used to showcase what happens when an exception is thrown
*
* @author Michael Isvy
* <p/>
* Also see how the bean of type 'SimpleMappingExceptionResolver' has been declared inside
* /WEB-INF/mvc-core-config.xml
* <p/>
* Also see how a view that resolves to "error" has been added ("error.html").
*/
@Controller
public class CrashController {
@RequestMapping(value = "/oups", method = RequestMethod.GET)
public String triggerException() {
throw new RuntimeException("Expected: controller used to showcase what " +
"happens when an exception is thrown");
throw new RuntimeException(
"Expected: controller used to showcase what " + "happens when an exception is thrown");
}
}
/*
* 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.web;
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";
}
}
......@@ -18,7 +18,6 @@ package org.springframework.samples.petclinic.web;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.samples.petclinic.model.Vets;
import org.springframework.samples.petclinic.service.ClinicService;
import org.springframework.stereotype.Controller;
......@@ -36,32 +35,28 @@ public class VetController {
private final ClinicService clinicService;
@Autowired
public VetController(ClinicService clinicService) {
this.clinicService = clinicService;
}
@RequestMapping(value = {"/vets.html"})
@RequestMapping(value = { "/vets.html" })
public String showVetList(Map<String, Object> model) {
// Here we are returning an object of type 'Vets' rather than a collection of Vet objects
// so it is simpler for Object-Xml mapping
// Here we are returning an object of type 'Vets' rather than a collection of Vet
// objects so it is simpler for Object-Xml mapping
Vets vets = new Vets();
vets.getVetList().addAll(this.clinicService.findVets());
model.put("vets", vets);
return "vets/vetList";
}
@RequestMapping(value = {"/vets.json", "/vets.xml"})
public
@ResponseBody
Vets showResourcesVetList() {
// Here we are returning an object of type 'Vets' rather than a collection of Vet objects
// so it is simpler for JSon/Object mapping
@RequestMapping(value = { "/vets.json", "/vets.xml" })
public @ResponseBody Vets showResourcesVetList() {
// Here we are returning an object of type 'Vets' rather than a collection of Vet
// objects so it is simpler for JSon/Object mapping
Vets vets = new Vets();
vets.getVetList().addAll(this.clinicService.findVets());
return vets;
}
}
......@@ -89,10 +89,4 @@ public class VisitController {
}
}
@RequestMapping(value = "/owners/*/pets/{petId}/visits", method = RequestMethod.GET)
public String showVisits(@PathVariable int petId, Map<String, Object> model) {
model.put("visits", this.clinicService.findPetById(petId).getVisits());
return "visitList";
}
}
......@@ -11,9 +11,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@import "../generated/META-INF/resources/webjars/bootstrap/3.3.6/less/bootstrap.less";
@import "META-INF/resources/webjars/bootstrap/3.3.6/less/bootstrap.less";
@icon-font-path: "../../webjars/bootstrap/3.3.6/fonts/";
@icon-font-path: "../../webjars/bootstrap/fonts/";
@spring-green: #6db33f;
@spring-dark-green: #5fa134;
......
......@@ -4,8 +4,7 @@ spring.datasource.schema=classpath*:db/${database}/schema.sql
spring.datasource.data=classpath*:db/${database}/data.sql
# Web
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
spring.thymeleaf.mode=HTML
# JPA
spring.jpa.hibernate.ddl-auto=none
......@@ -18,6 +17,7 @@ management.contextPath=/manage
# Logging
logging.level.org.springframework=INFO
logging.level.org.springframework.web=DEBUG
# Active Spring profiles
spring.profiles.active=production
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment