У меня есть рабочая реализация Spring Boot с Tomcat, которая прекрасно обрабатывает файл JAR в среде Linux. Тот же код не работает с Google Cloud. Я пытаюсь заставить JPA работать.
Облако Google предпочитает Jetty, а не Tomcat. Это может относиться к моей проблеме, но я не уверен, как это исправить. У меня есть рекомендуемое по умолчанию преобразование из стандартного Spring Boot JAR в WAR-версию для AppEngine Google Cloud. Мои зависимости работают нормально, если я попробую их в заданном проекте с сайта spring.io. Я не использую базы данных, поэтому я вырезал MySQL, что по умолчанию.
Моя проблема связана с отсутствующим EntityManagerFactory . Поскольку я стараюсь держать этот пост кратким, я просто включаю то, что считаю жизненно важным. Вы можете найти основы для всего проекта по адресу: https://github.com/shatterblast/spring-sylveria_fix-search
По сути, я не могу вызвать консоль администратора для этого проекта GCP. Проект и консоль администратора отвечают 503 на запрос. При запуске сообщения об ошибке нет, и оно работает нормально. После настройки кода я обнаружил бин EntityManager в качестве самой проблемы. Переименование бинов не помогло.
Спасибо.
import com.weslange.springboot.sylveria.entity.Gamer;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import javax.persistence.EntityManager;
@Repository
public class GamerDAOHibernateImpl implements GamerDAO {
private EntityManager entityManager;
@Autowired
public GamerDAOHibernateImpl( EntityManager theEntityManager ) {
entityManager = theEntityManager;
}
@Override
public Gamer findById( int id ) {
Session currentSession = entityManager.unwrap( Session.class );
Gamer gamer = currentSession.get( Gamer.class, id );
return gamer;
}
@Override
public void save( Gamer gamer ) {
Session currentSession = entityManager.unwrap( Session.class );
currentSession.saveOrUpdate( gamer );
}
}
.
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import javax.persistence.EntityManager;
@Repository
public class TokenDAOHibernateImpl implements TokenDAO {
private EntityManager entityManager;
@Autowired
public TokenDAOHibernateImpl(EntityManager theEntityManager) {
entityManager = theEntityManager;
}
}
.
import com.weslange.springboot.sylveria.SylveriaServerApplication;
import com.weslange.springboot.sylveria.entity.Token;
import com.weslange.springboot.sylveria.service.GamerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@RestController
@RequestMapping( "/" )
public class TokenRestController {
private static final Logger logger = LoggerFactory.getLogger( SylveriaServerApplication.class );
private GamerService gamerService;
@Autowired
public TokenRestController( GamerService gamerService ) {
gamerService = gamerService;
}
@PostMapping( "/" )
public HashMap addEmployee( @RequestBody Token token, HttpServletRequest request ) {
HashMap<String, String> returnMap = new HashMap();
returnMap.put( "sylveriaConnectionSuccess", "true" );
return returnMap;
}
}