Guest User

Untitled

a guest
Jun 24th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.09 KB | None | 0 0
  1. ***************************
  2. APPLICATION FAILED TO START
  3. ***************************
  4.  
  5. Description:
  6.  
  7. Parameter 0 of constructor in com.maximmalikov.onlineshop.service.CharacteristicsService required a bean of type 'com.maximmalikov.onlineshop.repository.GoodsRepository' that could not be found.
  8.  
  9.  
  10. Action:
  11.  
  12. Consider defining a bean of type 'com.maximmalikov.onlineshop.repository.GoodsRepository' in your configuration.
  13.  
  14.  
  15. Process finished with exit code 0
  16.  
  17. <?xml version="1.0" encoding="UTF-8"?>
  18. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  19. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  20. <modelVersion>4.0.0</modelVersion>
  21.  
  22. <groupId>com.maximmalikov</groupId>
  23. <artifactId>onlineshop</artifactId>
  24. <version>0.0.1-SNAPSHOT</version>
  25. <packaging>jar</packaging>
  26.  
  27. <name>onlineshop</name>
  28. <description>Onlineshop project for Spring Boot</description>
  29.  
  30. <parent>
  31. <groupId>org.springframework.boot</groupId>
  32. <artifactId>spring-boot-starter-parent</artifactId>
  33. <version>2.0.3.RELEASE</version>
  34. <relativePath/> <!-- lookup parent from repository -->
  35. </parent>
  36.  
  37. <properties>
  38. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  39. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  40. <java.version>1.8</java.version>
  41. </properties>
  42.  
  43. <dependencies>
  44. <dependency>
  45. <groupId>org.springframework.boot</groupId>
  46. <artifactId>spring-boot-starter-data-jpa</artifactId>
  47. </dependency>
  48. <dependency>
  49. <groupId>org.springframework.boot</groupId>
  50. <artifactId>spring-boot-starter-security</artifactId>
  51. </dependency>
  52. <dependency>
  53. <groupId>org.springframework.boot</groupId>
  54. <artifactId>spring-boot-starter-thymeleaf</artifactId>
  55. </dependency>
  56. <dependency>
  57. <groupId>org.springframework.boot</groupId>
  58. <artifactId>spring-boot-starter-web</artifactId>
  59. </dependency>
  60.  
  61. <dependency>
  62. <groupId>org.springframework.boot</groupId>
  63. <artifactId>spring-boot-devtools</artifactId>
  64. <scope>runtime</scope>
  65. </dependency>
  66. <dependency>
  67. <groupId>mysql</groupId>
  68. <artifactId>mysql-connector-java</artifactId>
  69. <scope>runtime</scope>
  70. </dependency>
  71. <dependency>
  72. <groupId>org.projectlombok</groupId>
  73. <artifactId>lombok</artifactId>
  74. <optional>true</optional>
  75. </dependency>
  76. <dependency>
  77. <groupId>org.springframework.boot</groupId>
  78. <artifactId>spring-boot-starter-test</artifactId>
  79. <scope>test</scope>
  80. </dependency>
  81. <dependency>
  82. <groupId>org.springframework</groupId>
  83. <artifactId>spring-orm</artifactId>
  84. </dependency>
  85. <dependency>
  86. <groupId>org.springframework.security</groupId>
  87. <artifactId>spring-security-test</artifactId>
  88. <scope>test</scope>
  89. </dependency>
  90. </dependencies>
  91.  
  92. <build>
  93. <plugins>
  94. <plugin>
  95. <groupId>org.springframework.boot</groupId>
  96. <artifactId>spring-boot-maven-plugin</artifactId>
  97. </plugin>
  98. </plugins>
  99. </build>
  100.  
  101.  
  102. </project>
  103.  
  104. @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, WebMvcAutoConfiguration.class})
  105. @SpringBootApplication
  106. public class OnlineshopApplication {
  107.  
  108. public static void main(String[] args) {
  109. SpringApplication.run(OnlineshopApplication.class, args);
  110. }
  111.  
  112. }
  113.  
  114. @Repository
  115. public interface CharacteristicsRepository extends JpaRepository<Characteristics,Long> {
  116.  
  117. Characteristics getByCharacteristicId(long characteristicsId);
  118.  
  119. Characteristics getByProductProductId(long productId);
  120.  
  121. }
  122.  
  123. @Service
  124. @RequiredArgsConstructor(onConstructor = @__(@Autowired))
  125. public class CharacteristicsService {
  126.  
  127. private final GoodsRepository goodsRepository;
  128.  
  129. private final CharacteristicsRepository characteristicsRepository;
  130.  
  131. private CharacteristicsDTO fromCharacteristics(Characteristics characteristic) {
  132. if (characteristic != null) {
  133. return CharacteristicsDTO.builder()
  134. .characteristicId(characteristic.getCharacteristicId())
  135. .characteristicName(characteristic.getCharacteristicName())
  136. .description(characteristic.getDescription())
  137. .product(characteristic.getProduct().getProductId())
  138. .build();
  139. }
  140. return null;
  141. }
  142.  
  143. private Characteristics fromDTO(CharacteristicsDTO characteristicsDTO) {
  144. if (characteristicsDTO != null) {
  145. return Characteristics.builder()
  146. .characteristicId(characteristicsDTO.getCharacteristicId())
  147. .characteristicName(characteristicsDTO.getCharacteristicName())
  148. .description(characteristicsDTO.getDescription())
  149. .product(characteristicsDTO.getProduct() > 0L
  150. ? goodsRepository.getOne(characteristicsDTO.getProduct())
  151. : null)
  152. .build();
  153. }
  154. return null;
  155. }
  156.  
  157. public List<CharacteristicsDTO> getAllCharacteristics() {
  158. return characteristicsRepository.findAll().stream()
  159. .map(this::fromCharacteristics)
  160. .collect(Collectors.toList());
  161. }
  162.  
  163. @Transactional
  164. public CharacteristicsDTO addCharacteristic(CharacteristicsDTO characteristicsDTO) {
  165. if (!characteristicsRepository.existsById(characteristicsDTO.getCharacteristicId())) {
  166. return fromCharacteristics(characteristicsRepository.saveAndFlush(fromDTO(characteristicsDTO)));
  167. }
  168. return null;
  169. }
  170.  
  171. @Transactional
  172. public void deleteByCharacteristicId(long characteristicId) {
  173. if (characteristicsRepository.existsById(characteristicId)) {
  174. characteristicsRepository.deleteById(characteristicId);
  175. }
  176. }
  177.  
  178. @Transactional
  179. public CharacteristicsDTO updateCharacteristics(CharacteristicsDTO characteristicsDTO) {
  180. if (characteristicsRepository.existsById(characteristicsDTO.getCharacteristicId())) {
  181. Characteristics characteristicsTemp = characteristicsRepository.getOne(characteristicsDTO.getCharacteristicId());
  182. characteristicsTemp.setCharacteristicName(characteristicsDTO.getCharacteristicName());
  183. characteristicsTemp.setDescription(characteristicsDTO.getDescription());
  184. return fromCharacteristics(characteristicsRepository.saveAndFlush(characteristicsTemp));
  185. }
  186. return null;
  187. }
  188.  
  189. public CharacteristicsDTO getByCharacteristicId(long characteristicId) {
  190. if (characteristicsRepository.existsById(characteristicId)) {
  191. return fromCharacteristics(characteristicsRepository.getByCharacteristicId(characteristicId));
  192. }
  193. return null;
  194. }
  195.  
  196. public CharacteristicsDTO getByProductId(long productId) {
  197. if (characteristicsRepository.existsById(productId)) {
  198. return fromCharacteristics(characteristicsRepository.getByProductProductId(productId));
  199. }
  200. return null;
  201. }
  202.  
  203. }
  204.  
  205. @RestController
  206. @RequestMapping("/characteristics")
  207. @RequiredArgsConstructor(onConstructor = @__(@Autowired))
  208. public class CharacteristicsController {
  209.  
  210. private final CharacteristicsService characteristicsService;
  211.  
  212. @GetMapping
  213. public List<CharacteristicsDTO> getAll() {
  214. return characteristicsService.getAllCharacteristics();
  215. }
  216.  
  217. @PostMapping
  218. public ResponseEntity<CharacteristicsDTO> addCharacteristic(@RequestBody CharacteristicsDTO characteristicsDTO) {
  219. CharacteristicsDTO characteristicsDTO1 = characteristicsService.addCharacteristic(characteristicsDTO);
  220. return ResponseEntity.ok(characteristicsDTO1);
  221. }
  222.  
  223. @DeleteMapping("/{characteristic_id}")
  224. public ResponseEntity<Void> deleteCharacteristic(@PathVariable(value = "characteristic_id") long characteristicId) {
  225. try {
  226. characteristicsService.deleteByCharacteristicId(characteristicId);
  227. return ResponseEntity.ok().build();
  228. } catch (Exception e) {
  229. return ResponseEntity.badRequest().build();
  230. }
  231. }
  232.  
  233. @PutMapping
  234. public ResponseEntity<CharacteristicsDTO> updateCharacteristic(@RequestBody CharacteristicsDTO characteristicsDTO) {
  235. CharacteristicsDTO characteristicsDTO1 = characteristicsService.updateCharacteristics(characteristicsDTO);
  236. return ResponseEntity.ok(characteristicsDTO1);
  237. }
  238.  
  239. @GetMapping("/{characteristic_id}")
  240. public ResponseEntity<CharacteristicsDTO> getCharacteristicById(@PathVariable(value = "characteristic_id") long characteristicId) {
  241. return ResponseEntity.ok(characteristicsService.getByCharacteristicId(characteristicId));
  242. }
  243.  
  244. @GetMapping("/goods/{product_id}")
  245. public ResponseEntity<CharacteristicsDTO> getCharacteristicByProductId(@PathVariable(value = "product_id") long productId) {
  246. return ResponseEntity.ok(characteristicsService.getByProductId(productId));
  247. }
  248.  
  249. }
  250.  
  251. spring.jpa.hibernate.ddl-auto=update
  252. spring.datasource.url=jdbc:mysql://localhost:3306/onlineshopbd?useSSL=false
  253. spring.datasource.username=root
  254. spring.datasource.password=malikovmaxim1997
  255.  
  256. spring.jpa.show-sql=true
  257. spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
  258. spring.jpa.open-in-view = true
  259.  
  260. <dependency>
  261. <groupId>org.hibernate</groupId>
  262. <artifactId>hibernate-entitymanager</artifactId>
  263. <version>5.2.17.Final</version>
  264. </dependency>
  265.  
  266. @Service
  267. @RequiredArgsConstructor(onConstructor = @__(@Autowired))
  268. public class CharacteristicsService {
  269.  
  270. private final GoodsRepository goodsRepository;
  271.  
  272. @Service
  273. public class CharacteristicsService {
  274.  
  275. @AutoWired
  276. private final GoodsRepository goodsRepository;
  277.  
  278. @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, WebMvcAutoConfiguration.class})
  279. @SpringBootApplication
  280. public class OnlineshopApplication {
Add Comment
Please, Sign In to add comment