【发布时间】:2021-05-09 21:37:41
【问题描述】:
当我运行我的主类时,我得到了这个错误:
Java HotSpot(TM) 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.I don't understand why it still gives an error .
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.5)
2021-05-10 00:26:58.833 INFO 2704 --- [ main] k.io.northwind.NorthwindApplication : Starting NorthwindApplication using Java 16.0.1 on VEYSEL with PID 2704 (C:\javaKamp\northwind\target\classes started by veyse in C:\javaKamp\northwind)
2021-05-10 00:26:58.835 INFO 2704 --- [ main] k.io.northwind.NorthwindApplication : No active profile set, falling back to default profiles: default
2021-05-10 00:26:59.348 INFO 2704 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-05-10 00:26:59.354 INFO 2704 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-05-10 00:26:59.355 INFO 2704 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.45]
2021-05-10 00:26:59.396 INFO 2704 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-05-10 00:26:59.396 INFO 2704 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 528 ms
2021-05-10 00:26:59.420 WARN 2704 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productsController' defined in file [C:\javaKamp\northwind\target\classes\kodlama\io\northwind\api\controllers\ProductsController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productManager' defined in file [C:\javaKamp\northwind\target\classes\kodlama\io\northwind\business\concretes\ProductManager.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'kodlama.io.northwind.dataAccess.abstracts.ProductDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2021-05-10 00:26:59.422 INFO 2704 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2021-05-10 00:26:59.429 INFO 2704 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-05-10 00:26:59.437 ERROR 2704 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in kodlama.io.northwind.business.concretes.ProductManager required a bean of type 'kodlama.io.northwind.dataAccess.abstracts.ProductDao' that could not be found.
Action:
Consider defining a bean of type 'kodlama.io.northwind.dataAccess.abstracts.ProductDao' in your configuration.
Process finished with exit code 1
ProductDao 接口:
package kodlama.io.northwind.dataAccess.abstracts;
import kodlama.io.northwind.entities.concretes.Product;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ProductDao extends JpaRepository<Product,Integer> { //interface interface'i extend eder. Product Türünde ve PK int olacak.
}
ProductManager 类:
package kodlama.io.northwind.business.concretes;
import kodlama.io.northwind.business.abstracts.ProductService;
import kodlama.io.northwind.dataAccess.abstracts.ProductDao;
import kodlama.io.northwind.entities.concretes.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service//springe bu class service görevi görecek dedik.
public class ProductManager implements ProductService {
private ProductDao productDao;
@Autowired //spring arkaplanda paroductDao sınıfı newleyip üretir.
public ProductManager(ProductDao productDao) {
super();
this.productDao = productDao;
}
@Override
public List<Product> getAll() {
return this.productDao.findAll(); //tüm verileri getir.
}
}
Pom xml
<?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>org.example</groupId>
<artifactId>northwind</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.14.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<version>2.4.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.4.5</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
</project>
主类
package kodlamaio.northwind;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@SpringBootApplication
@EnableJpaRepositories
public class NorthwindApplication {
public static void main(String[] args) {
SpringApplication.run(NorthwindApplication.class, args);
}
}
我不明白为什么它仍然给出错误。我不明白为什么它仍然给出错误。我不明白为什么它仍然给出错误。 我不明白为什么它仍然给出错误。 我不明白为什么它仍然给出错误。
【问题讨论】:
标签: java spring spring-boot hibernate