BAEL-1779 deploy springboot app to azure

This commit is contained in:
aiet
2018-05-23 16:46:55 +08:00
parent 4c333aeeb3
commit 94f50c2175
10 changed files with 311 additions and 0 deletions
@@ -0,0 +1,19 @@
package com.baeldung.springboot.azure;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class AzureApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(AzureApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(AzureApplication.class, args);
}
}
@@ -0,0 +1,34 @@
package com.baeldung.springboot.azure;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import static com.baeldung.springboot.azure.User.userNamed;
/**
* @author aiet
*/
@RestController
public class TestController {
@GetMapping("/hello")
public String hello() {
return "hello azure!";
}
@Autowired private UserRepository userRepository;
@PostMapping("/user")
public String register(@RequestParam String name) {
userRepository.save(userNamed(name));
return "registered";
}
@GetMapping("/user")
public Iterable<User> userlist() {
return userRepository.findAll();
}
}
@@ -0,0 +1,43 @@
package com.baeldung.springboot.azure;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
/**
* @author aiet
*/
@Entity
public class User {
public User() {
}
public static User userNamed(String name) {
User u = new User();
u.setName(name);
return u;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
private String name;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@@ -0,0 +1,9 @@
package com.baeldung.springboot.azure;
import org.springframework.data.repository.CrudRepository;
/**
* @author aiet
*/
public interface UserRepository extends CrudRepository<User, Long> {
}
@@ -0,0 +1,16 @@
server.port=8080
server.address=0.0.0.0
spring.jpa.hibernate.ddl-auto=create
logging.file=azure.log
logging.level.root=info
spring.datasource.url=jdbc:h2:file:~/test
spring.datasource.username=sa
spring.datasource.password=
#spring.datasource.url=jdbc:mysql://localhost:3306/localdb
#spring.datasource.username=your-db-username
#spring.datasource.password=your-db-password