title: UnsatisfiedDependencyException: Error creating bean with name
body: <p>i'm trying to create db server on Spring, and  looked through a lot of similar questions, but no one answer to them can't help me. I can't solve this Error:</p>
  
  <blockquote>
    <p>org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'groupController': Unsatisfied dependency expressed through field 'gs'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'groupServiceImpl': Unsatisfied dependency expressed through field 'gr'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'groupRepository': Cannot create inner bean '(inner bean)#1a3c15e0' 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)#1a3c15e0': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available</p>
  </blockquote>
  
  <p>So here's my classes :</p>
  
  <p><strong>GroupController.java</strong></p>
  
  <pre><code> @RestController
  public class GroupController {
  
      @Autowired
      private GroupService gs;
  
  
      @RequestMapping(value = "/groups", method = RequestMethod.GET)
      @ResponseBody
      public List&lt;Group&gt; getAllGroups(){
         // return mocklist();
          return gs.getAll();
      }
  
      private List&lt;Group&gt; mocklist() {
          Group g= new Group();
          g.setId(1);
          g.setGroupName("333");
          g.setTutorName("shcefsa");
          List&lt;Group&gt; list = new ArrayList&lt;Group&gt;();
          list.add(g);
          g.setId(2);
          g.setGroupName("333");
          g.setTutorName("shc321efsa");
          list.add(g);
          return list;
      }
  
  
      @RequestMapping(value = "/groups/{id}", method = RequestMethod.GET)
      @ResponseBody
      public Group getGroupById(@PathVariable("id") int groupId){
          return gs.getById(groupId);
      }
  
  
      @RequestMapping(value = "/groups", method = RequestMethod.POST)
      @ResponseBody
      public Group addGroup(@RequestBody Group group){
          return gs.add(group);
      }
  
  
      @RequestMapping(value = "/groups", method = RequestMethod.POST)
      @ResponseBody
      public Group updateGroup(@RequestBody Group group){
          return gs.add(group);
      }
  
      @RequestMapping(value = "/groups/{id}", method = RequestMethod.POST)
      @ResponseBody
      public void deleteGroup(@PathVariable("id") int groupId){
          gs.deleteById(groupId);
      }
  
  
  }
  </code></pre>
  
  <p><strong>GroupRepository.java</strong></p>
  
  <pre><code>@Repository
  public interface GroupRepository extends JpaRepository&lt;Group, Integer&gt; {
  
  
  }
  </code></pre>
  
  <p><strong>GroupService.java</strong></p>
  
  <pre><code>@Service
  public interface GroupService {
  
      List&lt;Group&gt; getAll();
      Group getById(int id);
      Group add(Group group);
      void deleteById(int id);
  
  }
  </code></pre>
  
  <p><strong>GroupServiceImpl.java</strong>`</p>
  
  <pre><code>@Service
  public class GroupServiceImpl implements GroupService {
  @Autowired
  private GroupRepository gr;
  
  public List&lt;Group&gt; getAll() {
      return gr.findAll();
  }
  
  public Group getById(int id) {
      return gr.findOne(id);
  }
  
  public Group add(Group group) {
      return gr.save(group);
  }
  
  public void deleteById(int id) {
      gr.delete(id);
  }
  </code></pre>
  
  <p>Looking at other answers, it seems that everything is fine, but it's obvious that there's an error. Hope you'll help me</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p><strong>Databaseconfig.java</strong></p>
  
  <pre><code>    @Configuration
  @EnableJpaRepositories("com.homestudio.tutor.server.repository")
  @EnableTransactionManagement
  @PropertySource("classpath:db.properties")
  @ComponentScan("com.homestudio.tutor.server")
  public class DatabaseConfig {
  
  
      @Resource
      private Environment env;
  
      @Bean
      public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean(){
          LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
          em.setDataSource(dataSource());
          em.setPackagesToScan(env.getRequiredProperty("db.entity.package"));
          em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
          em.setJpaProperties(getHibernateProperties());
  
          return em;
      }
  
  
  
      @Bean
      public PlatformTransactionManager platformTransactionManager(){
          JpaTransactionManager manager = new JpaTransactionManager();
          manager.setEntityManagerFactory(entityManagerFactoryBean().getObject());
  
          return manager;
  
      }
  
  
      @Bean
      public DataSource dataSource(){
          BasicDataSource ds = new BasicDataSource();
          ds.setUrl(env.getRequiredProperty("db.url"));
          ds.setDriverClassName(env.getRequiredProperty("db.driver"));
          ds.setUsername(env.getRequiredProperty("db.username"));
          ds.setPassword(env.getRequiredProperty("db.password"));
  
          ds.setInitialSize(Integer.valueOf(env.getRequiredProperty("db.initialSize")));
          ds.setMinIdle(Integer.valueOf(env.getRequiredProperty("db.minIdle")));
          ds.setMaxIdle(Integer.valueOf(env.getRequiredProperty("db.maxIdle")));
          ds.setTimeBetweenEvictionRunsMillis(Long.valueOf(env.getRequiredProperty("db.timeBetweenEvictionRunsMilles")));
          ds.setMinEvictableIdleTimeMillis(Long.valueOf(env.getRequiredProperty("db.minEvictableIdleTimeMilles")));
          ds.setTestOnBorrow(Boolean.valueOf(env.getRequiredProperty("db.testOnBorrow")));
          ds.setValidationQuery(env.getRequiredProperty("db.validationQuery"));
  
          return ds;
  
      }
  
      public Properties getHibernateProperties() {
  
          try {
          Properties properties = new Properties();
          InputStream is = getClass().getClassLoader().getResourceAsStream("hibernate.properties");
  
          properties.load(is);
  
              return properties;
          } catch (IOException e) {
              throw new IllegalArgumentException("Cannot find file \"hibernate.properties\" in classpath");
          }
  
  
  
      }
  }
  </code></pre>
  
  <p><strong>WebConfig.java</strong></p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  @ComponentScan("com.homestudio.tutor.server")
  public class WebConfig extends WebMvcConfigurerAdapter{
  
      @Override
      public void configureMessageConverters(List&lt;HttpMessageConverter&lt;?&gt;&gt; converters) {
          MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
          converter.setObjectMapper(new ObjectMapper());
          converter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));
  
  
          converters.add(converter);
  
      }
  }
  </code></pre>