После запуска приложение фейлится. Не могу понять в чем ошибка. Перелазил интернет, но что-то пока не нашел ответа. Вот описание:
Description:
Field userRepository in com.pro100denysko.app.resttest.controller.UserController required a bean of type 'com.pro100denysko.app.resttest.service.UserRepository' that could not be found.
Action:
Consider defining a bean of type 'com.pro100denysko.app.resttest.service.UserRepository' in your configuration.
Вот контроллер:
package com.pro100denysko.app.resttest.controller;
import com.pro100denysko.app.resttest.model.User;
import com.pro100denysko.app.resttest.service.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/users")
public class UserController {
@Autowired
UserRepository userRepository;
@RequestMapping(value = "/listOfUsers", method = RequestMethod.GET)
@ResponseBody
public List<User> findAll() {
return userRepository.findAll();
}
}
Вот модель:
package com.pro100denysko.app.resttest.model;
import lombok.Data;
import javax.persistence.*;
@Entity
@Table(name = "users")
public @Data
class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private int id;
@Column(name = "NAME")
private String name;
@Column(name = "LASTNAME")
private String lastName;
@Column(name = "AGE")
private int age;
}
Вот сервис репозитория:
package com.pro100denysko.app.resttest.service;
import com.pro100denysko.app.resttest.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository("UserRepository")
public interface UserRepository extends JpaRepository<User, Integer> {
}
Ну и сам Мейн:
package com.pro100denysko.app.resttest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan(basePackages = {"com.pro100denysko.app.resttest"})
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class})
public class RestTestApplication {
public static void main(String[] args) {
SpringApplication.run(RestTestApplication.class, args);
}
}
RestTestApplication
докинуть@EnableJpaRepositories(basePackages = {"com.pro100denysko.app.resttest"})
– Nofate♦ 21 сен '17 в 16:32Consider defining a bean named 'entityManagerFactory' in your configuration
. – Pro100Denysko 21 сен '17 в 16:37