Guest User

Untitled

a guest
Jun 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.88 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 named 'entityManagerFactory' that could not be found.
  8.  
  9.  
  10. Action:
  11.  
  12. Consider defining a bean named 'entityManagerFactory' 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.hibernate</groupId>
  87. <artifactId>hibernate-core</artifactId>
  88. <version>5.3.1.Final</version>
  89. </dependency>
  90. <dependency>
  91. <groupId>org.hibernate</groupId>
  92. <artifactId>hibernate-entitymanager</artifactId>
  93. <version>5.3.1.Final</version>
  94. </dependency>
  95. <dependency>
  96. <groupId>org.springframework.security</groupId>
  97. <artifactId>spring-security-test</artifactId>
  98. <scope>test</scope>
  99. </dependency>
  100. </dependencies>
  101.  
  102. <build>
  103. <plugins>
  104. <plugin>
  105. <groupId>org.springframework.boot</groupId>
  106. <artifactId>spring-boot-maven-plugin</artifactId>
  107. </plugin>
  108. </plugins>
  109. </build>
  110.  
  111.  
  112. </project>
  113.  
  114. @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, WebMvcAutoConfiguration.class})
  115. @EnableJpaRepositories(basePackages = "com.maximmalikov.onlineshop.repository")
  116. @EnableTransactionManagement
  117. @SpringBootApplication
  118. public class OnlineshopApplication {
  119.  
  120. public static void main(String[] args) {
  121. SpringApplication.run(OnlineshopApplication.class, args);
  122. }
  123.  
  124. }
  125.  
  126. @Repository
  127. public interface CharacteristicsRepository extends JpaRepository<Characteristics,Long> {
  128.  
  129. Characteristics getByCharacteristicId(long characteristicsId);
  130.  
  131. Characteristics getByProductProductId(long productId);
  132.  
  133. }
  134.  
  135. @Service
  136. @RequiredArgsConstructor(onConstructor = @__(@Autowired))
  137. public class CharacteristicsService {
  138.  
  139. private final GoodsRepository goodsRepository;
  140.  
  141. private final CharacteristicsRepository characteristicsRepository;
  142.  
  143. private CharacteristicsDTO fromCharacteristics(Characteristics characteristic) {
  144. if (characteristic != null) {
  145. return CharacteristicsDTO.builder()
  146. .characteristicId(characteristic.getCharacteristicId())
  147. .characteristicName(characteristic.getCharacteristicName())
  148. .description(characteristic.getDescription())
  149. .product(characteristic.getProduct().getProductId())
  150. .build();
  151. }
  152. return null;
  153. }
  154.  
  155. private Characteristics fromDTO(CharacteristicsDTO characteristicsDTO) {
  156. if (characteristicsDTO != null) {
  157. return Characteristics.builder()
  158. .characteristicId(characteristicsDTO.getCharacteristicId())
  159. .characteristicName(characteristicsDTO.getCharacteristicName())
  160. .description(characteristicsDTO.getDescription())
  161. .product(characteristicsDTO.getProduct() > 0L
  162. ? goodsRepository.getOne(characteristicsDTO.getProduct())
  163. : null)
  164. .build();
  165. }
  166. return null;
  167. }
  168.  
  169. public List<CharacteristicsDTO> getAllCharacteristics() {
  170. return characteristicsRepository.findAll().stream()
  171. .map(this::fromCharacteristics)
  172. .collect(Collectors.toList());
  173. }
  174.  
  175. @Transactional
  176. public CharacteristicsDTO addCharacteristic(CharacteristicsDTO characteristicsDTO) {
  177. if (!characteristicsRepository.existsById(characteristicsDTO.getCharacteristicId())) {
  178. return fromCharacteristics(characteristicsRepository.saveAndFlush(fromDTO(characteristicsDTO)));
  179. }
  180. return null;
  181. }
  182.  
  183. @Transactional
  184. public void deleteByCharacteristicId(long characteristicId) {
  185. if (characteristicsRepository.existsById(characteristicId)) {
  186. characteristicsRepository.deleteById(characteristicId);
  187. }
  188. }
  189.  
  190. @Transactional
  191. public CharacteristicsDTO updateCharacteristics(CharacteristicsDTO characteristicsDTO) {
  192. if (characteristicsRepository.existsById(characteristicsDTO.getCharacteristicId())) {
  193. Characteristics characteristicsTemp = characteristicsRepository.getOne(characteristicsDTO.getCharacteristicId());
  194. characteristicsTemp.setCharacteristicName(characteristicsDTO.getCharacteristicName());
  195. characteristicsTemp.setDescription(characteristicsDTO.getDescription());
  196. return fromCharacteristics(characteristicsRepository.saveAndFlush(characteristicsTemp));
  197. }
  198. return null;
  199. }
  200.  
  201. public CharacteristicsDTO getByCharacteristicId(long characteristicId) {
  202. if (characteristicsRepository.existsById(characteristicId)) {
  203. return fromCharacteristics(characteristicsRepository.getByCharacteristicId(characteristicId));
  204. }
  205. return null;
  206. }
  207.  
  208. public CharacteristicsDTO getByProductId(long productId) {
  209. if (characteristicsRepository.existsById(productId)) {
  210. return fromCharacteristics(characteristicsRepository.getByProductProductId(productId));
  211. }
  212. return null;
  213. }
  214.  
  215. }
  216.  
  217. @RestController
  218. @RequestMapping("/characteristics")
  219. @RequiredArgsConstructor(onConstructor = @__(@Autowired))
  220. public class CharacteristicsController {
  221.  
  222. private final CharacteristicsService characteristicsService;
  223.  
  224. @GetMapping
  225. public List<CharacteristicsDTO> getAll() {
  226. return characteristicsService.getAllCharacteristics();
  227. }
  228.  
  229. @PostMapping
  230. public ResponseEntity<CharacteristicsDTO> addCharacteristic(@RequestBody CharacteristicsDTO characteristicsDTO) {
  231. CharacteristicsDTO characteristicsDTO1 = characteristicsService.addCharacteristic(characteristicsDTO);
  232. return ResponseEntity.ok(characteristicsDTO1);
  233. }
  234.  
  235. @DeleteMapping("/{characteristic_id}")
  236. public ResponseEntity<Void> deleteCharacteristic(@PathVariable(value = "characteristic_id") long characteristicId) {
  237. try {
  238. characteristicsService.deleteByCharacteristicId(characteristicId);
  239. return ResponseEntity.ok().build();
  240. } catch (Exception e) {
  241. return ResponseEntity.badRequest().build();
  242. }
  243. }
  244.  
  245. @PutMapping
  246. public ResponseEntity<CharacteristicsDTO> updateCharacteristic(@RequestBody CharacteristicsDTO characteristicsDTO) {
  247. CharacteristicsDTO characteristicsDTO1 = characteristicsService.updateCharacteristics(characteristicsDTO);
  248. return ResponseEntity.ok(characteristicsDTO1);
  249. }
  250.  
  251. @GetMapping("/{characteristic_id}")
  252. public ResponseEntity<CharacteristicsDTO> getCharacteristicById(@PathVariable(value = "characteristic_id") long characteristicId) {
  253. return ResponseEntity.ok(characteristicsService.getByCharacteristicId(characteristicId));
  254. }
  255.  
  256. @GetMapping("/goods/{product_id}")
  257. public ResponseEntity<CharacteristicsDTO> getCharacteristicByProductId(@PathVariable(value = "product_id") long productId) {
  258. return ResponseEntity.ok(characteristicsService.getByProductId(productId));
  259. }
  260.  
  261. }
  262.  
  263. spring.jpa.hibernate.ddl-auto=update
  264. spring.datasource.url=jdbc:mysql://localhost:3306/onlineshopbd?useSSL=false
  265. spring.datasource.username=root
  266. spring.datasource.password=malikovmaxim1997
  267.  
  268. spring.jpa.show-sql=true
  269. spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
  270. spring.jpa.open-in-view = true
Add Comment
Please, Sign In to add comment