Spring Boot doesn\'t work with Google App Engine (at least not for me).
However much of the examples written or available in the GitHub or other repositorie
Just created this example for you:
src/main/webapp/WEB-INF/spring/context.xml
${hibernate.dialect}
/src/main/webapp/WEB-INF/spring/jdbc.properties
# JDBC Connection
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://host:3306/db
jdbc.username=user
jdbc.password=password
hibernate.dialect=org.hibernate.dialect.MySQLDialect
/src/main/webapp/WEB-INF/spring/servlet-context.xml
web.xml
contextConfigLocation
/WEB-INF/spring/context.xml
webAppRootKey
demo_jpa
org.springframework.web.context.ContextLoaderListener
appServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
/WEB-INF/spring/servlet-context.xml
1
appServlet
/
pom.xml
4.1.7.RELEASE
4.3.8.Final
1.9.0.RELEASE
1.4
5.1.28
UTF-8
org.springframework
spring-context-support
${org.springframework-version}
org.springframework
spring-webmvc
${org.springframework-version}
org.springframework.data
spring-data-jpa
${org.springframework.data-version}
org.hibernate
hibernate-entitymanager
${org.hibernate-em-version}
mysql
mysql-connector-java
${mysql-connector-version}
commons-dbcp
commons-dbcp
${dbcp-version}
Data Entity: com.demo.data.User
package com.demo.data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "SYS_USERS")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "USER_ID")
private int id;
@Column(name = "USER_NAME")
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Spring Data JPA Repository: com.demo.data.UserRepository
package com.demo.data;
import org.springframework.data.repository.CrudRepository;
public interface UserRepository extends CrudRepository {
}
Service
Interface:
package com.demo.svc;
import com.demo.data.User;
public interface UserService {
User findUserById(Integer id);
}
Implementation:
package com.demo.svc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.demo.data.User;
import com.demo.data.UserRepository;
@Service
public class UserServiceImpl implements UserService {
@Autowired
UserRepository userRepository;
public User findUserById(Integer id) {
return userRepository.findOne(id);
}
}
Web Controller: com.demo.web.UserController
package com.demo.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.demo.svc.UserService;
@Controller
public class UserController {
@Autowired
UserService svc;
@RequestMapping("/")
@ResponseBody
public String test() {
return svc.findUserById(1).getName();
}
}