Spring Boot Development Using Command Line Only
https://www.youtube.com/watch?v=zmnlpf4FtkE
https://www.developersoapbox.com/command-line-only-spring-boot-development-using-vim/
https://www.developersoapbox.com/creating-a-rest-api-effortlessly-with-spring-rest-repositories/
$ sudo apt install vim tmux curl unzip
$ mkdir -p ~/projects/dev/java/spring && cd ~/projects/dev/java/spring
$ curl https://start.spring.io/starter.zip -d dependencies=h2,data-jpa,data-rest,lombok -d javaVersion=11 -o demo.zip
$ unzip demo.zip
$ ./mvnw spring-boot:run
$ vi src/main/java/com/example/demo/Beer.java
package com.example.demo;
import javax.annotation.Generated;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.GenerationType;
import lombok.Data;
@Data
@Entity
public class Beer {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
private String name;
private Double abv;
}
$ vi src/main/java/com/example/demo/RestRepository.java
package com.example.demo;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
@RepositoryRestResource
public interface RestRepository extends CrudRepository<Beer, Long>{}
$ mkdir -p src/main/resources/
$ vi src/main/resources/application.properties
spring.jpa.defer-datasource-initialization=true
spring.datasource.url=jdbc:h2:mem:test
spring.jpa.hibernate.ddl-auto=create-drop
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.show-sql=true
$ vi src/main/resources/data.sql
INSERT INTO beer(name,abv) VALUES('Kozel', 9.0);
INSERT INTO beer(name,abv) VALUES('Carlsberg', 9.0);
INSERT INTO beer(name,abv) VALUES('Heineken', 7.5);
INSERT INTO beer(name,abv) VALUES('Tuborg', 5.0);
INSERT INTO beer(name,abv) VALUES('Bochka', 6.2);
COMMIT;
$ ./mvnw spring-boot:run
$ curl http://localhost:8080/beers
$ curl -X POST -H "Content-Type:application/json" -d '{"name": "Klinskoe", "abv": 7.5}' http://localhost:8080/beers
$ curl http://localhost:8080/beers/
OK!