├── target └── classes │ ├── persistence.xml │ ├── application.properties │ └── com │ └── zanclus │ ├── Application.class │ ├── api │ └── CustomerEndpoints.class │ └── data │ ├── access │ └── CustomerDAO.class │ └── entities │ └── Customer.class ├── src └── main │ ├── resources │ ├── persistence.xml │ └── application.properties │ └── java │ └── com │ └── zanclus │ ├── data │ ├── access │ │ └── CustomerDAO.java │ └── entities │ │ └── Customer.java │ ├── SecurityConfig.java │ ├── api │ └── CustomerEndpoints.java │ └── Application.java ├── .gitignore ├── README.md └── pom.xml /target/classes/persistence.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/persistence.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /target/classes/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .idea/** 3 | .mvn 4 | .mvn/** 5 | spring-vertx-conversion.iml 6 | mvnw 7 | mvnw.cmd 8 | target 9 | target/** -------------------------------------------------------------------------------- /target/classes/com/zanclus/Application.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JUGGL/Spring-Vert.x-Integration-Example/HEAD/target/classes/com/zanclus/Application.class -------------------------------------------------------------------------------- /target/classes/com/zanclus/api/CustomerEndpoints.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JUGGL/Spring-Vert.x-Integration-Example/HEAD/target/classes/com/zanclus/api/CustomerEndpoints.class -------------------------------------------------------------------------------- /target/classes/com/zanclus/data/access/CustomerDAO.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JUGGL/Spring-Vert.x-Integration-Example/HEAD/target/classes/com/zanclus/data/access/CustomerDAO.class -------------------------------------------------------------------------------- /target/classes/com/zanclus/data/entities/Customer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JUGGL/Spring-Vert.x-Integration-Example/HEAD/target/classes/com/zanclus/data/entities/Customer.class -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Spring Application Vert.x Integration Example 2 | ============================================= 3 | 4 | # Overview 5 | This application demonstrates converting a standard Spring Data/REST application to take advantage of Vert.x capabilties 6 | -------------------------------------------------------------------------------- /src/main/java/com/zanclus/data/access/CustomerDAO.java: -------------------------------------------------------------------------------- 1 | package com.zanclus.data.access; 2 | 3 | import com.zanclus.data.entities.Customer; 4 | import org.springframework.data.repository.CrudRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * A Spring Data JPA {@link Repository} which implements the default CRUD operations for the {@link Customer} entity 9 | */ 10 | @Repository 11 | public interface CustomerDAO extends CrudRepository { 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/zanclus/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.zanclus; 2 | 3 | import org.springframework.boot.autoconfigure.security.SecurityProperties; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.core.annotation.Order; 6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 7 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 8 | 9 | /** 10 | * Disable all security checks. DO NOT USE THIS IN PRODUCTION! YOU WILL GET HACKED! YOU HAVE BEEN WARNED!!! 11 | */ 12 | @Configuration 13 | @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER) 14 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 15 | protected void configure(HttpSecurity http) throws Exception { 16 | http.authorizeRequests() 17 | .anyRequest().anonymous().anyRequest().permitAll(); 18 | http.csrf().disable(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/zanclus/data/entities/Customer.java: -------------------------------------------------------------------------------- 1 | package com.zanclus.data.entities; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | import lombok.Data; 6 | import lombok.experimental.Accessors; 7 | 8 | import javax.persistence.*; 9 | 10 | /** 11 | * A JPA annotated POJO representing a Customer entity 12 | */ 13 | @Data 14 | @Accessors(fluent = true, chain = true) 15 | @Entity 16 | @Table(name = "customers") 17 | public class Customer { 18 | 19 | @Id 20 | @GeneratedValue(strategy = GenerationType.SEQUENCE) 21 | @JsonProperty("id") 22 | private Long id; 23 | 24 | @Column 25 | @JsonProperty("name") 26 | private String name; 27 | 28 | @Column(name = "street_addr_1") 29 | @JsonProperty("street_addr_1") 30 | private String streetAddress1; 31 | 32 | @Column(name = "street_addr_2") 33 | @JsonProperty("street_addr_2") 34 | private String streetAddress2; 35 | 36 | @Column 37 | @JsonProperty("city") 38 | private String city; 39 | 40 | @Column 41 | @JsonProperty("province") 42 | private String province; 43 | 44 | @Column 45 | @JsonProperty("country") 46 | private String country; 47 | 48 | @Column(name = "post_code") 49 | private String postalCode; 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/zanclus/api/CustomerEndpoints.java: -------------------------------------------------------------------------------- 1 | package com.zanclus.api; 2 | 3 | import com.zanclus.data.access.CustomerDAO; 4 | import com.zanclus.data.entities.Customer; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | import java.util.List; 10 | import java.util.stream.Collectors; 11 | import java.util.stream.StreamSupport; 12 | 13 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 14 | import static org.springframework.web.bind.annotation.RequestMethod.PUT; 15 | 16 | /** 17 | * {@link RestController} for {@link Customer} documents. 18 | */ 19 | @RestController 20 | @RequestMapping(value = "/v1/customer", produces="application/json") 21 | @Slf4j 22 | public class CustomerEndpoints { 23 | @Autowired 24 | private CustomerDAO dao; 25 | 26 | /** 27 | * Return a list of all {@link Customer}s from the database 28 | * @return A {@link List} of {@link Customer} objects representing all customers from the database 29 | */ 30 | @RequestMapping(method=GET) 31 | public @ResponseBody List findAll() { 32 | return StreamSupport.stream(dao.findAll().spliterator(), false).collect(Collectors.toList()); 33 | } 34 | 35 | /** 36 | * Return the {@link Customer} identified 37 | * @param id The ID of the {@link Customer} to be returned. 38 | * @return A {@link Customer} document or {@code null} if not found. 39 | */ 40 | @RequestMapping(value="/{id}", method=GET) 41 | public @ResponseBody Customer findById(@PathVariable("id") Long id) { 42 | return dao.findOne(id); 43 | } 44 | 45 | /** 46 | * Adds a new {@link Customer} entity to the database as specified by the JSON document in the PUT request. 47 | * @param customer The JSON body of the PUT request is automatically translated into a {@link Customer} entity 48 | * @return The persisted {@link Customer} entity after the {@code id} has been set. 49 | * @throws Exception 50 | */ 51 | @RequestMapping(method=PUT, consumes="application/json") 52 | public @ResponseBody Customer addCustomer(@RequestBody Customer customer) throws Exception { 53 | return dao.save(customer); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.zanclus 7 | spring-vertx-demo 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | demo 12 | Spring To Vert.x Conversion Project 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.2.7.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-data-jpa 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-data-rest 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-security 38 | 39 | 40 | org.projectlombok 41 | lombok 42 | 1.16.6 43 | 44 | 45 | hsqldb 46 | hsqldb 47 | 1.8.0.10 48 | 49 | 50 | org.slf4j 51 | slf4j-api 52 | 1.7.12 53 | 54 | 55 | org.apache.logging.log4j 56 | log4j-slf4j-impl 57 | 2.4 58 | 59 | 60 | org.apache.logging.log4j 61 | log4j-core 62 | 2.4 63 | 64 | 65 | org.apache.logging.log4j 66 | log4j-api 67 | 2.4 68 | 69 | 70 | org.springframework.boot 71 | spring-boot-starter-test 72 | test 73 | 74 | 75 | 76 | 77 | 78 | 79 | org.springframework.boot 80 | spring-boot-maven-plugin 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /src/main/java/com/zanclus/Application.java: -------------------------------------------------------------------------------- 1 | package com.zanclus; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 9 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; 10 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; 11 | import org.springframework.orm.jpa.JpaTransactionManager; 12 | import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; 13 | import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; 14 | import org.springframework.transaction.PlatformTransactionManager; 15 | import org.springframework.transaction.annotation.EnableTransactionManagement; 16 | 17 | import javax.persistence.EntityManagerFactory; 18 | import javax.sql.DataSource; 19 | 20 | /** 21 | * Entry point for the application via Spring Boot. Bootstraps the dependency injection framework and sets up the 22 | * injectable resources for database connectivity 23 | */ 24 | @SpringBootApplication 25 | @EnableJpaRepositories 26 | @EnableTransactionManagement 27 | @Slf4j 28 | public class Application { 29 | public static void main(String[] args) { 30 | ApplicationContext ctx = SpringApplication.run(Application.class, args); 31 | } 32 | 33 | /** 34 | * Creates a datasource using an in-memory embedded database 35 | * @return 36 | */ 37 | @Bean 38 | public DataSource dataSource() { 39 | EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); 40 | return builder.setType(EmbeddedDatabaseType.HSQL).build(); 41 | } 42 | 43 | /** 44 | * Creates a JPA {@link EntityManagerFactory} for use in Spring Data JPA 45 | * @return An instance of {@link EntityManagerFactory} 46 | */ 47 | @Bean 48 | public EntityManagerFactory entityManagerFactory() { 49 | HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); 50 | vendorAdapter.setGenerateDdl(true); 51 | 52 | LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); 53 | factory.setJpaVendorAdapter(vendorAdapter); 54 | factory.setPackagesToScan("com.zanclus.data.entities"); 55 | factory.setDataSource(dataSource()); 56 | factory.afterPropertiesSet(); 57 | 58 | return factory.getObject(); 59 | } 60 | 61 | /** 62 | * Sets up transaction management for Spring Data JPA so that database operations are transactional 63 | * @param emf The {@link javax.persistence.EntityManagerFactory} created above 64 | * @return An instance of {@link PlatformTransactionManager} based on JPA 65 | */ 66 | @Bean 67 | public PlatformTransactionManager transactionManager(final EntityManagerFactory emf) { 68 | final JpaTransactionManager txManager = new JpaTransactionManager(); 69 | txManager.setEntityManagerFactory(emf); 70 | return txManager; 71 | } 72 | } 73 | --------------------------------------------------------------------------------