Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
- 2018-06-24 15:55:37.651 ERROR 6924 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
- 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'?
- at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
- at...
- Process finished with exit code 0
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>com.maximmalikov</groupId>
- <artifactId>onlineshop</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>jar</packaging>
- <name>onlineshop</name>
- <description>Onlineshop project for Spring Boot</description>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.0.3.RELEASE</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
- <java.version>1.8</java.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-data-jpa</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-security</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-thymeleaf</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-devtools</artifactId>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-orm</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.security</groupId>
- <artifactId>spring-security-test</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
- </project>
- @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, WebMvcAutoConfiguration.class})
- @SpringBootApplication
- public class OnlineshopApplication {
- public static void main(String[] args) {
- SpringApplication.run(OnlineshopApplication.class, args);
- }
- }
- @Repository
- public interface OrdersRepository extends JpaRepository<Orders,Long> {
- Orders getByOrderNumber(long orderNumber);
- Orders getByOrderDate(Date orderDate);
- Orders getByGoodsProductId(Goods productId);
- Orders getByGoodsProductName(Goods productName);
- }
- @Service
- @RequiredArgsConstructor(onConstructor = @__(@Autowired))
- public class OrdersService {
- private final OrdersRepository ordersRepository;
- private final GoodsRepository goodsRepository;
- private final UsersRepository usersRepository;
- private final DeliveryRepository deliveryRepository;
- private OrdersDTO fromOrders(Orders order) {
- if (order != null) {
- return OrdersDTO.builder()
- .orderNumber(order.getOrderNumber())
- .orderDate(order.getOrderDate())
- .orderTime(order.getOrderTime())
- .orderStatus(order.getOrderStatus())
- .paymentMethod(order.getPaymentMethod())
- .goods(order.getGoods() != null
- ? order.getGoods().stream()
- .map(Goods::getProductId)
- .collect(Collectors.toList())
- : null)
- .users(order.getUsers() != null
- ? order.getUsers().stream()
- .map(Users::getUserId)
- .collect(Collectors.toList())
- : null)
- .delivery(order.getDelivery().getOrderNumber())
- .build();
- }
- return null;
- }
- private Orders fromDTO(OrdersDTO ordersDTO) {
- if (ordersDTO != null) {
- return Orders.builder()
- .orderNumber(ordersDTO.getOrderNumber())
- .orderDate(ordersDTO.getOrderDate())
- .orderTime(ordersDTO.getOrderTime())
- .orderStatus(ordersDTO.getOrderStatus())
- .paymentMethod(ordersDTO.getPaymentMethod())
- .goods(ordersDTO.getGoods() != null
- ? goodsRepository.findAllById(ordersDTO.getGoods())
- : null)
- .users(ordersDTO.getUsers() != null
- ? usersRepository.findAllById(ordersDTO.getUsers())
- : null)
- .delivery(ordersDTO.getDelivery() > 0L
- ? deliveryRepository.getOne(ordersDTO.getDelivery())
- : null)
- .build();
- }
- return null;
- }
- public List<OrdersDTO> getAllOrders() {
- return ordersRepository.findAll().stream()
- .map(this::fromOrders)
- .collect(Collectors.toList());
- }
- @Transactional
- public OrdersDTO addOrder(OrdersDTO ordersDTO) {
- if (!ordersRepository.existsById(ordersDTO.getOrderNumber())) {
- return fromOrders(ordersRepository.saveAndFlush(fromDTO(ordersDTO)));
- }
- return null;
- }
- @Transactional
- public void deleteByOrderNumber(long orderNumber) {
- if (ordersRepository.existsById(orderNumber)) {
- ordersRepository.deleteById(orderNumber);
- }
- }
- @Transactional
- public OrdersDTO updateOrder(OrdersDTO ordersDTO) {
- if (ordersRepository.existsById(ordersDTO.getOrderNumber())) {
- Orders ordersTemp = ordersRepository.getOne(ordersDTO.getOrderNumber());
- ordersTemp.setOrderDate(ordersDTO.getOrderDate());
- ordersTemp.setOrderTime(ordersDTO.getOrderTime());
- ordersTemp.setOrderStatus(ordersDTO.getOrderStatus());
- ordersTemp.setPaymentMethod(ordersDTO.getPaymentMethod());
- return fromOrders(ordersRepository.saveAndFlush(ordersTemp));
- }
- return null;
- }
- public OrdersDTO getByOrderNumber(long orderNumber) {
- if (ordersRepository.existsById(orderNumber)) {
- return fromOrders(ordersRepository.getByOrderNumber(orderNumber));
- }
- return null;
- }
- public OrdersDTO getByOrderDate(Date orderDate) {
- return fromOrders(ordersRepository.getByOrderDate(orderDate));
- }
- public OrdersDTO getByProductId(Goods product) {
- return fromOrders(ordersRepository.getByGoodsProductId(goodsRepository.getByProductId(product.getProductId())));
- }
- public OrdersDTO getByProductName(Goods product) {
- return fromOrders(ordersRepository.getByGoodsProductName(goodsRepository.getByProductName(product.getProductName())));
- }
- }
- @RestController
- @RequestMapping("/orders")
- @RequiredArgsConstructor(onConstructor = @__(@Autowired))
- public class OrdersController {
- private final OrdersService ordersService;
- private final GoodsRepository goodsRepository;
- @GetMapping
- public List<OrdersDTO> getAll() {
- return ordersService.getAllOrders();
- }
- @PostMapping
- public ResponseEntity<OrdersDTO> addOrder(@RequestBody OrdersDTO ordersDTO) {
- OrdersDTO ordersDTO1 = ordersService.addOrder(ordersDTO);
- return ResponseEntity.ok(ordersDTO1);
- }
- @DeleteMapping("/{order_number}")
- public ResponseEntity<Void> deleteOrder(@PathVariable(value = "order_number") long orderNumber) {
- try {
- ordersService.deleteByOrderNumber(orderNumber);
- return ResponseEntity.ok().build();
- } catch (Exception e) {
- return ResponseEntity.badRequest().build();
- }
- }
- @PutMapping
- public ResponseEntity<OrdersDTO> updateOrder(@RequestBody OrdersDTO ordersDTO) {
- OrdersDTO ordersDTO1 = ordersService.updateOrder(ordersDTO);
- return ResponseEntity.ok(ordersDTO1);
- }
- @GetMapping("/{order_number}")
- public ResponseEntity<OrdersDTO> getOrderByNumber(@PathVariable(value = "order_number") long orderNumber) {
- return ResponseEntity.ok(ordersService.getByOrderNumber(orderNumber));
- }
- @GetMapping("/{order_date}")
- public ResponseEntity<OrdersDTO> getOrderByDate(@PathVariable(value = "order_date") Date orderDate) {
- return ResponseEntity.ok(ordersService.getByOrderDate(orderDate));
- }
- @GetMapping("/goods/{product_id}")
- public ResponseEntity<OrdersDTO> getOrderByProductId(@PathVariable(value = "product_id") long productId) {
- return ResponseEntity.ok(ordersService.getByProductId(goodsRepository.getByProductId(productId)));
- }
- @GetMapping("/goods/{product_name}")
- public ResponseEntity<OrdersDTO> getOrderByProductName(@PathVariable(value = "product_name") String productName) {
- return ResponseEntity.ok(ordersService.getByProductName(goodsRepository.getByProductName(productName)));
- }
- }
- spring.jpa.hibernate.ddl-auto=update
- spring.datasource.url=jdbc:mysql://localhost:3306/onlineshopbd?useSSL=false
- spring.datasource.username=root
- spring.datasource.password=malikovmaxim1997
- spring.jpa.show-sql=true
- spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
- spring.jpa.open-in-view = true
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-entitymanager</artifactId>
- <version>5.2.17.Final</version>
- </dependency>
- @Service
- @RequiredArgsConstructor(onConstructor = @__(@Autowired))
- public class CharacteristicsService {
- private final GoodsRepository goodsRepository;
- @Service
- public class CharacteristicsService {
- @AutoWired
- private final GoodsRepository goodsRepository;
- @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, WebMvcAutoConfiguration.class})
- @SpringBootApplication
- public class OnlineshopApplication {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement