Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.33 KB | None | 0 0
  1. Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
  2. 2018-06-24 15:55:37.651 ERROR 6924 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
  3.  
  4. org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'deliveryController' defined in file [D:MaxJavaWorksDiplomOnlineShoptargetclassescommaximmalikovonlineshoprestDeliveryController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'deliveryService' defined in file [D:MaxJavaWorksDiplomOnlineShoptargetclassescommaximmalikovonlineshopserviceDeliveryService.class]: Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ordersRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract com.maximmalikov.onlineshop.domain.Orders com.maximmalikov.onlineshop.repository.OrdersRepository.getByUserId(com.maximmalikov.onlineshop.domain.Users)! No property userId found for type Orders! Did you mean 'users'?
  5. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
  6. at...
  7.  
  8. Process finished with exit code 0
  9.  
  10. <?xml version="1.0" encoding="UTF-8"?>
  11. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  12. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  13. <modelVersion>4.0.0</modelVersion>
  14.  
  15. <groupId>com.maximmalikov</groupId>
  16. <artifactId>onlineshop</artifactId>
  17. <version>0.0.1-SNAPSHOT</version>
  18. <packaging>jar</packaging>
  19.  
  20. <name>onlineshop</name>
  21. <description>Onlineshop project for Spring Boot</description>
  22.  
  23. <parent>
  24. <groupId>org.springframework.boot</groupId>
  25. <artifactId>spring-boot-starter-parent</artifactId>
  26. <version>2.0.3.RELEASE</version>
  27. <relativePath/> <!-- lookup parent from repository -->
  28. </parent>
  29.  
  30. <properties>
  31. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  32. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  33. <java.version>1.8</java.version>
  34. </properties>
  35.  
  36. <dependencies>
  37. <dependency>
  38. <groupId>org.springframework.boot</groupId>
  39. <artifactId>spring-boot-starter-data-jpa</artifactId>
  40. </dependency>
  41. <dependency>
  42. <groupId>org.springframework.boot</groupId>
  43. <artifactId>spring-boot-starter-security</artifactId>
  44. </dependency>
  45. <dependency>
  46. <groupId>org.springframework.boot</groupId>
  47. <artifactId>spring-boot-starter-thymeleaf</artifactId>
  48. </dependency>
  49. <dependency>
  50. <groupId>org.springframework.boot</groupId>
  51. <artifactId>spring-boot-starter-web</artifactId>
  52. </dependency>
  53.  
  54. <dependency>
  55. <groupId>org.springframework.boot</groupId>
  56. <artifactId>spring-boot-devtools</artifactId>
  57. <scope>runtime</scope>
  58. </dependency>
  59. <dependency>
  60. <groupId>mysql</groupId>
  61. <artifactId>mysql-connector-java</artifactId>
  62. <scope>runtime</scope>
  63. </dependency>
  64. <dependency>
  65. <groupId>org.projectlombok</groupId>
  66. <artifactId>lombok</artifactId>
  67. <optional>true</optional>
  68. </dependency>
  69. <dependency>
  70. <groupId>org.springframework.boot</groupId>
  71. <artifactId>spring-boot-starter-test</artifactId>
  72. <scope>test</scope>
  73. </dependency>
  74. <dependency>
  75. <groupId>org.springframework</groupId>
  76. <artifactId>spring-orm</artifactId>
  77. </dependency>
  78. <dependency>
  79. <groupId>org.springframework.security</groupId>
  80. <artifactId>spring-security-test</artifactId>
  81. <scope>test</scope>
  82. </dependency>
  83. </dependencies>
  84.  
  85. <build>
  86. <plugins>
  87. <plugin>
  88. <groupId>org.springframework.boot</groupId>
  89. <artifactId>spring-boot-maven-plugin</artifactId>
  90. </plugin>
  91. </plugins>
  92. </build>
  93.  
  94.  
  95. </project>
  96.  
  97. @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, WebMvcAutoConfiguration.class})
  98. @SpringBootApplication
  99. public class OnlineshopApplication {
  100.  
  101. public static void main(String[] args) {
  102. SpringApplication.run(OnlineshopApplication.class, args);
  103. }
  104.  
  105. }
  106.  
  107. @Repository
  108. public interface OrdersRepository extends JpaRepository<Orders,Long> {
  109.  
  110. Orders getByOrderNumber(long orderNumber);
  111.  
  112. Orders getByOrderDate(Date orderDate);
  113.  
  114. Orders getByGoodsProductId(Goods productId);
  115.  
  116. Orders getByGoodsProductName(Goods productName);
  117.  
  118. }
  119.  
  120. @Service
  121. @RequiredArgsConstructor(onConstructor = @__(@Autowired))
  122. public class OrdersService {
  123.  
  124. private final OrdersRepository ordersRepository;
  125.  
  126. private final GoodsRepository goodsRepository;
  127.  
  128. private final UsersRepository usersRepository;
  129.  
  130. private final DeliveryRepository deliveryRepository;
  131.  
  132. private OrdersDTO fromOrders(Orders order) {
  133. if (order != null) {
  134. return OrdersDTO.builder()
  135. .orderNumber(order.getOrderNumber())
  136. .orderDate(order.getOrderDate())
  137. .orderTime(order.getOrderTime())
  138. .orderStatus(order.getOrderStatus())
  139. .paymentMethod(order.getPaymentMethod())
  140. .goods(order.getGoods() != null
  141. ? order.getGoods().stream()
  142. .map(Goods::getProductId)
  143. .collect(Collectors.toList())
  144. : null)
  145. .users(order.getUsers() != null
  146. ? order.getUsers().stream()
  147. .map(Users::getUserId)
  148. .collect(Collectors.toList())
  149. : null)
  150. .delivery(order.getDelivery().getOrderNumber())
  151. .build();
  152. }
  153. return null;
  154. }
  155.  
  156. private Orders fromDTO(OrdersDTO ordersDTO) {
  157. if (ordersDTO != null) {
  158. return Orders.builder()
  159. .orderNumber(ordersDTO.getOrderNumber())
  160. .orderDate(ordersDTO.getOrderDate())
  161. .orderTime(ordersDTO.getOrderTime())
  162. .orderStatus(ordersDTO.getOrderStatus())
  163. .paymentMethod(ordersDTO.getPaymentMethod())
  164. .goods(ordersDTO.getGoods() != null
  165. ? goodsRepository.findAllById(ordersDTO.getGoods())
  166. : null)
  167. .users(ordersDTO.getUsers() != null
  168. ? usersRepository.findAllById(ordersDTO.getUsers())
  169. : null)
  170. .delivery(ordersDTO.getDelivery() > 0L
  171. ? deliveryRepository.getOne(ordersDTO.getDelivery())
  172. : null)
  173. .build();
  174. }
  175. return null;
  176. }
  177.  
  178. public List<OrdersDTO> getAllOrders() {
  179. return ordersRepository.findAll().stream()
  180. .map(this::fromOrders)
  181. .collect(Collectors.toList());
  182. }
  183.  
  184. @Transactional
  185. public OrdersDTO addOrder(OrdersDTO ordersDTO) {
  186. if (!ordersRepository.existsById(ordersDTO.getOrderNumber())) {
  187. return fromOrders(ordersRepository.saveAndFlush(fromDTO(ordersDTO)));
  188. }
  189. return null;
  190. }
  191.  
  192. @Transactional
  193. public void deleteByOrderNumber(long orderNumber) {
  194. if (ordersRepository.existsById(orderNumber)) {
  195. ordersRepository.deleteById(orderNumber);
  196. }
  197. }
  198.  
  199. @Transactional
  200. public OrdersDTO updateOrder(OrdersDTO ordersDTO) {
  201. if (ordersRepository.existsById(ordersDTO.getOrderNumber())) {
  202. Orders ordersTemp = ordersRepository.getOne(ordersDTO.getOrderNumber());
  203. ordersTemp.setOrderDate(ordersDTO.getOrderDate());
  204. ordersTemp.setOrderTime(ordersDTO.getOrderTime());
  205. ordersTemp.setOrderStatus(ordersDTO.getOrderStatus());
  206. ordersTemp.setPaymentMethod(ordersDTO.getPaymentMethod());
  207. return fromOrders(ordersRepository.saveAndFlush(ordersTemp));
  208. }
  209. return null;
  210. }
  211.  
  212. public OrdersDTO getByOrderNumber(long orderNumber) {
  213. if (ordersRepository.existsById(orderNumber)) {
  214. return fromOrders(ordersRepository.getByOrderNumber(orderNumber));
  215. }
  216. return null;
  217. }
  218.  
  219. public OrdersDTO getByOrderDate(Date orderDate) {
  220. return fromOrders(ordersRepository.getByOrderDate(orderDate));
  221. }
  222.  
  223. public OrdersDTO getByProductId(Goods product) {
  224. return fromOrders(ordersRepository.getByGoodsProductId(goodsRepository.getByProductId(product.getProductId())));
  225. }
  226.  
  227. public OrdersDTO getByProductName(Goods product) {
  228. return fromOrders(ordersRepository.getByGoodsProductName(goodsRepository.getByProductName(product.getProductName())));
  229. }
  230.  
  231. }
  232.  
  233. @RestController
  234. @RequestMapping("/orders")
  235. @RequiredArgsConstructor(onConstructor = @__(@Autowired))
  236. public class OrdersController {
  237.  
  238. private final OrdersService ordersService;
  239. private final GoodsRepository goodsRepository;
  240.  
  241.  
  242. @GetMapping
  243. public List<OrdersDTO> getAll() {
  244. return ordersService.getAllOrders();
  245. }
  246.  
  247. @PostMapping
  248. public ResponseEntity<OrdersDTO> addOrder(@RequestBody OrdersDTO ordersDTO) {
  249. OrdersDTO ordersDTO1 = ordersService.addOrder(ordersDTO);
  250. return ResponseEntity.ok(ordersDTO1);
  251. }
  252.  
  253. @DeleteMapping("/{order_number}")
  254. public ResponseEntity<Void> deleteOrder(@PathVariable(value = "order_number") long orderNumber) {
  255. try {
  256. ordersService.deleteByOrderNumber(orderNumber);
  257. return ResponseEntity.ok().build();
  258. } catch (Exception e) {
  259. return ResponseEntity.badRequest().build();
  260. }
  261. }
  262.  
  263. @PutMapping
  264. public ResponseEntity<OrdersDTO> updateOrder(@RequestBody OrdersDTO ordersDTO) {
  265. OrdersDTO ordersDTO1 = ordersService.updateOrder(ordersDTO);
  266. return ResponseEntity.ok(ordersDTO1);
  267. }
  268.  
  269. @GetMapping("/{order_number}")
  270. public ResponseEntity<OrdersDTO> getOrderByNumber(@PathVariable(value = "order_number") long orderNumber) {
  271. return ResponseEntity.ok(ordersService.getByOrderNumber(orderNumber));
  272. }
  273.  
  274. @GetMapping("/{order_date}")
  275. public ResponseEntity<OrdersDTO> getOrderByDate(@PathVariable(value = "order_date") Date orderDate) {
  276. return ResponseEntity.ok(ordersService.getByOrderDate(orderDate));
  277. }
  278.  
  279. @GetMapping("/goods/{product_id}")
  280. public ResponseEntity<OrdersDTO> getOrderByProductId(@PathVariable(value = "product_id") long productId) {
  281. return ResponseEntity.ok(ordersService.getByProductId(goodsRepository.getByProductId(productId)));
  282. }
  283.  
  284. @GetMapping("/goods/{product_name}")
  285. public ResponseEntity<OrdersDTO> getOrderByProductName(@PathVariable(value = "product_name") String productName) {
  286. return ResponseEntity.ok(ordersService.getByProductName(goodsRepository.getByProductName(productName)));
  287. }
  288.  
  289.  
  290. }
  291.  
  292. spring.jpa.hibernate.ddl-auto=update
  293. spring.datasource.url=jdbc:mysql://localhost:3306/onlineshopbd?useSSL=false
  294. spring.datasource.username=root
  295. spring.datasource.password=malikovmaxim1997
  296.  
  297. spring.jpa.show-sql=true
  298. spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
  299. spring.jpa.open-in-view = true
  300.  
  301. <dependency>
  302. <groupId>org.hibernate</groupId>
  303. <artifactId>hibernate-entitymanager</artifactId>
  304. <version>5.2.17.Final</version>
  305. </dependency>
  306.  
  307. @Service
  308. @RequiredArgsConstructor(onConstructor = @__(@Autowired))
  309. public class CharacteristicsService {
  310.  
  311. private final GoodsRepository goodsRepository;
  312.  
  313. @Service
  314. public class CharacteristicsService {
  315.  
  316. @AutoWired
  317. private final GoodsRepository goodsRepository;
  318.  
  319. @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, WebMvcAutoConfiguration.class})
  320. @SpringBootApplication
  321. public class OnlineshopApplication {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement