У меня возникла ошибка при установке Swagger с помощью SpringJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 У меня возникла ошибка при установке Swagger с помощью Spring

Сообщение Anonymous »

Я пытаюсь разработать проект с помощью Spring и пытаюсь загрузить для этого «Swagger-ui». Но я всегда сталкиваюсь с проблемами. Ниже я расскажу вам об ошибках, которые я получаю, и поделюсь с вами файлами pom.xml, application.properties и application.java соответственно. Я использую postgresql в качестве базы данных и уверен, что пароль правильный.

Код: Выделить всё

    ***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

Action:

Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
Это лишь одна из ошибок, которые я получаю. Когда я вношу в него некоторые изменения, ошибка может превратиться в вот это.

Код: Выделить всё

      ***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist.  The attempt was made from the following location:

org.springframework.plugin.core.support.AbstractTypeAwareSupport$BeansOfTypeTargetSource.(AbstractTypeAwareSupport.java:135)

The following method did not exist:

'void org.springframework.util.Assert.notNull(java.lang.Object)'

The calling method's class, org.springframework.plugin.core.support.AbstractTypeAwareSupport$BeansOfTypeTargetSource, was loaded from the following location:

jar:file:/C:/Users/emirg/.m2/repository/org/springframework/plugin/spring-plugin-core/1.2.0.RELEASE/spring-plugin-core-1.2.0.RELEASE.jar!/org/springframework/plugin/core/support/AbstractTypeAwareSupport$BeansOfTypeTargetSource.class

The called method's class, org.springframework.util.Assert, is available from the following locations:

jar:file:/C:/Users/emirg/.m2/repository/org/springframework/spring-core/6.1.12/spring-core-6.1.12.jar!/org/springframework/util/Assert.class

The called method's class hierarchy was loaded from the following locations:

org.springframework.util.Assert: file:/C:/Users/emirg/.m2/repository/org/springframework/spring-core/6.1.12/spring-core-6.1.12.jar

Action:

Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.plugin.core.support.AbstractTypeAwareSupport$BeansOfTypeTargetSource and org.springframework.util.Assert
МОЙ ФАЙЛ pom.xml

Код: Выделить всё

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0

org.springframework.boot
spring-boot-starter-parent
3.3.3
  

kodlamaio
northwind
0.0.1-SNAPSHOT
northwind
Demo project for Spring Boot













17



org.springframework.boot
spring-boot-starter-data-jpa


org.springframework.boot
spring-boot-starter-web



org.springframework.boot
spring-boot-devtools
runtime
true


org.postgresql
postgresql
runtime


org.projectlombok
lombok
true


org.springframework.boot
spring-boot-starter-test
test


io.springfox
springfox-swagger2
2.9.2


io.springfox
springfox-swagger-ui
2.9.2





org.springframework.boot
spring-boot-maven-plugin



org.projectlombok
lombok









МОЕ приложение. СТРАНИЦА свойств

Код: Выделить всё

spring.application.name=northwind
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.show-sql=true
spring.datasource.url=jdbc:postgresql://localhost:5432/Northwind
spring.datasource.username=*****
spring.datasource.password=*****
spring.jpa.properties.javax.persistence.validation.mode = none
spring.datasource.driver-class-name=org.postgresql.Driver
spring.profiles.active=dev
МОЯ СТРАНИЦА NorthwindApplication.java

Код: Выделить всё

package kodlamaio.northwind;

import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.Bean;

import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableSwagger2
public class NorthwindApplication {

public static void main(String[] args) {
SpringApplication.run(NorthwindApplication.class, args);
}

@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("kodlamaio.northwind"))
.build();
}

}
МОЯ СТРАНИЦА ProductsController.java

Код: Выделить всё

package kodlamaio.northwind.api.controllers;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import kodlamaio.northwind.business.abstracts.ProductService;
import kodlamaio.northwind.entities.concretes.Product;

@RestController
@RequestMapping("/api/products")
public class ProductsController {

@Autowired
public ProductsController(ProductService productService) {
super();
this.productService = productService;
}

private ProductService productService;

@GetMapping("/getall")
public List
 getAll(){
return this.productService.getAll();

}

}
Затем я решил попробовать что-то другое, решил использовать openapi-ui и добавил следующее в свой файл pom.xml.

Код: Выделить всё

org.springdoc
springdoc-openapi-ui
1.7.0

Но на этот раз я столкнулся со следующей ошибкой на порту localhost:8080.

Код: Выделить всё

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sun Sep 01 16:06:17 TRT 2024
There was an unexpected error (type=Not Found, status=404).
No static resource swagger-ui.html.
org.springframework.web.servlet.resource.NoResourceFoundException: No static resource swagger-ui.html.
Я знаю, что между моими папками Spring и кодом, который я написал, есть несоответствие. Но я не знаю, как это исправить, а ChatGPT вообще не помог.

Подробнее здесь: https://stackoverflow.com/questions/789 ... ith-spring
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»