Answer the question
In order to leave comments, you need to log in
Why is the jpaRepository bean not being created?
Deploying for the first time. through the idea, everything works fine, but when you try to deploy to vps, it gives an error, the github project
Stackrace errors:
[main] WARN org.springframework.context.annotation.AnnotationConfigApplicationContext - Exception encountered during context initialization - cancel ling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bot' defined in URL [jar:file:/root/Telegr am.jar!/com/nikita/bot/Bot.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.Unsati sfiedDependencyException: Error creating bean with name 'channelService' defined in URL [jar:file:/root/Telegram.jar!/com/nikita/service/ChannelService.class]: U nsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaChannelRepository' defined in com.nikita.repository.JpaChannelRepository defined in @EnableJpaRepositories declared on App: Cannot create inner be an '(inner bean)#3382f8ae' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org. springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3382f8ae': Cannot resolve reference to bean 'entityManagerFactor y' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
21:43:19.367 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bot' defined in URL [jar:file:/root/Telegram.jar!/com/nikita/bot /Bot.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyExcepti on: Error creating bean with name 'channelService' defined in URL [jar:file:/root/Telegram.jar!/com/nikita/service/ChannelService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaChannel Repository' defined in com.nikita.repository.JpaChannelRepository defined in @EnableJpaRepositories declared on App: Cannot create inner bean '(inner bean)#3382f 8ae' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans. factory.BeanCreationException: Error creating bean with name '(inner bean)#3382f8ae': Cannot resolve reference to bean 'entityManagerFactory' while setting const ructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
import com.nikita.model.Channel;
import com.nikita.repository.JpaChannelRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ChannelService {
private final JpaChannelRepository jpaChannelRepository;
@Autowired
public ChannelService(JpaChannelRepository jpaChannelRepository) {
this.jpaChannelRepository = jpaChannelRepository;
}
public List<Channel> findByStart(boolean start){
return jpaChannelRepository.findAllByStart(start);
}
public Channel update(Channel channel){
return jpaChannelRepository.save(channel);
}
public void delete(String id){
jpaChannelRepository.deleteById(id);
}
public List<Channel> findAll(){
return jpaChannelRepository.findAll();
}
public Channel findById(String id){
return jpaChannelRepository.findById(id).get();
}
}
package com.nikita.repository;
import com.nikita.model.Channel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
public interface JpaChannelRepository extends JpaRepository<Channel, String> {
@Override
Optional<Channel> findById(String id);
@Query("SELECT c FROM Channel c WHERE c.start=:start")
List<Channel> findAllByStart(@Param("start") boolean start);
@Override
<S extends Channel> S save(S s);
@Override
void deleteById(String id);
}
Answer the question
In order to leave comments, you need to log in
It looks like you are missing the "entityManagerFactory" bean:
No bean named 'entityManagerFactory' available
Hello!
Did you manage to solve the problem?
If not, then I will share some thoughts, and you already debug your code.
Deploying for the first time. through the idea, everything works fine, but when you try to deploy to vps, it gives an error
hibernate.ddl-auto: validate
is installed and if it is installed, whether you have imported ddl & dml to the server. Or do you have it in production should create ddl itself? public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(App.class);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question