Spring Data JPA without Spring Boot

前端 未结 2 1953
春和景丽
春和景丽 2020-12-01 13:35

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

2条回答
  •  暖寄归人
    2020-12-01 14:32

    This is happening because you haven't created the bean of UserRepository in context. There are a number of ways you can do this since you're not using a spring boot project so it won't make an object in the container at startup due to which @Autowired is not injecting the object in the UserRepository class. For this project, you can update the following in your project:

     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 {
    
     UserRepository userRepository;
    
     public User findUserById(Integer id) {
         return userRepository.findOne(id);
     }
    
      public UserRepository setRepo(UserRepository repo)
      {
        userRepository=repo;
      }
    
    }
    

    Also, you'll need to inject the object from the container. In src/main/webapp/WEB-INF/spring/context.xml

    
    
    
    
    
     
     
    

    Hope it helps

提交回复
热议问题