Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ***************************
- APPLICATION FAILED TO START
- ***************************
- Description:
- 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.
- Action:
- Consider defining a bean of type 'com.maximmalikov.onlineshop.repository.GoodsRepository' in your configuration.
- 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 CharacteristicsRepository extends JpaRepository<Characteristics,Long> {
- Characteristics getByCharacteristicId(long characteristicsId);
- Characteristics getByProductProductId(long productId);
- }
- @Service
- @RequiredArgsConstructor(onConstructor = @__(@Autowired))
- public class CharacteristicsService {
- private final GoodsRepository goodsRepository;
- private final CharacteristicsRepository characteristicsRepository;
- private CharacteristicsDTO fromCharacteristics(Characteristics characteristic) {
- if (characteristic != null) {
- return CharacteristicsDTO.builder()
- .characteristicId(characteristic.getCharacteristicId())
- .characteristicName(characteristic.getCharacteristicName())
- .description(characteristic.getDescription())
- .product(characteristic.getProduct().getProductId())
- .build();
- }
- return null;
- }
- private Characteristics fromDTO(CharacteristicsDTO characteristicsDTO) {
- if (characteristicsDTO != null) {
- return Characteristics.builder()
- .characteristicId(characteristicsDTO.getCharacteristicId())
- .characteristicName(characteristicsDTO.getCharacteristicName())
- .description(characteristicsDTO.getDescription())
- .product(characteristicsDTO.getProduct() > 0L
- ? goodsRepository.getOne(characteristicsDTO.getProduct())
- : null)
- .build();
- }
- return null;
- }
- public List<CharacteristicsDTO> getAllCharacteristics() {
- return characteristicsRepository.findAll().stream()
- .map(this::fromCharacteristics)
- .collect(Collectors.toList());
- }
- @Transactional
- public CharacteristicsDTO addCharacteristic(CharacteristicsDTO characteristicsDTO) {
- if (!characteristicsRepository.existsById(characteristicsDTO.getCharacteristicId())) {
- return fromCharacteristics(characteristicsRepository.saveAndFlush(fromDTO(characteristicsDTO)));
- }
- return null;
- }
- @Transactional
- public void deleteByCharacteristicId(long characteristicId) {
- if (characteristicsRepository.existsById(characteristicId)) {
- characteristicsRepository.deleteById(characteristicId);
- }
- }
- @Transactional
- public CharacteristicsDTO updateCharacteristics(CharacteristicsDTO characteristicsDTO) {
- if (characteristicsRepository.existsById(characteristicsDTO.getCharacteristicId())) {
- Characteristics characteristicsTemp = characteristicsRepository.getOne(characteristicsDTO.getCharacteristicId());
- characteristicsTemp.setCharacteristicName(characteristicsDTO.getCharacteristicName());
- characteristicsTemp.setDescription(characteristicsDTO.getDescription());
- return fromCharacteristics(characteristicsRepository.saveAndFlush(characteristicsTemp));
- }
- return null;
- }
- public CharacteristicsDTO getByCharacteristicId(long characteristicId) {
- if (characteristicsRepository.existsById(characteristicId)) {
- return fromCharacteristics(characteristicsRepository.getByCharacteristicId(characteristicId));
- }
- return null;
- }
- public CharacteristicsDTO getByProductId(long productId) {
- if (characteristicsRepository.existsById(productId)) {
- return fromCharacteristics(characteristicsRepository.getByProductProductId(productId));
- }
- return null;
- }
- }
- @RestController
- @RequestMapping("/characteristics")
- @RequiredArgsConstructor(onConstructor = @__(@Autowired))
- public class CharacteristicsController {
- private final CharacteristicsService characteristicsService;
- @GetMapping
- public List<CharacteristicsDTO> getAll() {
- return characteristicsService.getAllCharacteristics();
- }
- @PostMapping
- public ResponseEntity<CharacteristicsDTO> addCharacteristic(@RequestBody CharacteristicsDTO characteristicsDTO) {
- CharacteristicsDTO characteristicsDTO1 = characteristicsService.addCharacteristic(characteristicsDTO);
- return ResponseEntity.ok(characteristicsDTO1);
- }
- @DeleteMapping("/{characteristic_id}")
- public ResponseEntity<Void> deleteCharacteristic(@PathVariable(value = "characteristic_id") long characteristicId) {
- try {
- characteristicsService.deleteByCharacteristicId(characteristicId);
- return ResponseEntity.ok().build();
- } catch (Exception e) {
- return ResponseEntity.badRequest().build();
- }
- }
- @PutMapping
- public ResponseEntity<CharacteristicsDTO> updateCharacteristic(@RequestBody CharacteristicsDTO characteristicsDTO) {
- CharacteristicsDTO characteristicsDTO1 = characteristicsService.updateCharacteristics(characteristicsDTO);
- return ResponseEntity.ok(characteristicsDTO1);
- }
- @GetMapping("/{characteristic_id}")
- public ResponseEntity<CharacteristicsDTO> getCharacteristicById(@PathVariable(value = "characteristic_id") long characteristicId) {
- return ResponseEntity.ok(characteristicsService.getByCharacteristicId(characteristicId));
- }
- @GetMapping("/goods/{product_id}")
- public ResponseEntity<CharacteristicsDTO> getCharacteristicByProductId(@PathVariable(value = "product_id") long productId) {
- return ResponseEntity.ok(characteristicsService.getByProductId(productId));
- }
- }
- 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 {
Add Comment
Please, Sign In to add comment