我正在尝试为我的项目做一个球员列表,有一个不同对象的工作应用程序,(书籍而不是球员)。我渴望得到帮助,因为我不能从这里开始进步…
有没有人知道为什么它会给我一个这样的错误?我需要发布更多信息吗?
这是我的PlayerApplication.java;
package fi.haagahelia.course;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import model.Pelaaja;
import model.PelaajaRepository;
import model.Rooli;
import model.RooliRepository;
import model.User;
import model.UserRepository;
@SpringBootApplication
public class PelaajaApplication {
private static final Logger log = LoggerFactory.getLogger(PelaajaApplication.class);
public static void main(String[] args) {
SpringApplication.run(PelaajaApplication.class, args);
}
@Bean
public CommandLineRunner pelaajaDemo(PelaajaRepository prepository, RooliRepository rorepository, UserRepository urepository) {
return (args) -> {
log.info("save two users");
User user1 = new User("eetu", "$2a$06$3jYRJrg0ghaaypjZ/.g4SethoeA51ph3UD4kZi9oPkeMTpjKU5uo6", "USER");
User user2 = new User("eetu2", "$2a$10$0MMwY.IQqpsVc1jC8u7IJ.2rT8b0Cd3b3sfIBGV2zfgnPGtT4r0.C", "ADMIN");
urepository.save(user1);
urepository.save(user2);
log.info("save a couple players");
rorepository.save(new Rooli("In-Game Leader"));
rorepository.save(new Rooli("Rifler"));
rorepository.save(new Rooli("AWP"));
prepository.save(new Pelaaja("Atte Ampuja", "1999", 150000, rorepository.findByName("Rifler").get(0)));
prepository.save(new Pelaaja("Joonas Joonaksela", "2005", 13, rorepository.findByName("AWP").get(0)));
prepository.save(new Pelaaja("Eetu Leppänen", "1999", 1500000, rorepository.findByName("In-Game Leader").get(0)));
log.info("fetch all players");
for (Pelaaja pelaaja : prepository.findAll()) {
log.info(pelaaja.toString());
}
};
}
}
但当我运行它时,这里是控制台:
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.3.RELEASE)
2020-11-15 00:50:17.538 INFO 15276 --- [ restartedMain] fi.haagahelia.course.PelaajaApplication : Starting PelaajaApplication on Calgary-PC with PID 15276 (C:\Users\Calgary\eclipse-workspace\koodaus\myllycs2020\target\classes started by Calgary in C:\Users\Calgary\eclipse-workspace\koodaus\myllycs2020)
2020-11-15 00:50:17.546 INFO 15276 --- [ restartedMain] fi.haagahelia.course.PelaajaApplication : No active profile set, falling back to default profiles: default
2020-11-15 00:50:17.638 INFO 15276 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-11-15 00:50:17.638 INFO 15276 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2020-11-15 00:50:18.780 INFO 15276 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2020-11-15 00:50:18.821 INFO 15276 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 28ms. Found 0 JPA repository interfaces.
2020-11-15 00:50:19.467 INFO 15276 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@3b43b0fc' of type [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-11-15 00:50:19.477 INFO 15276 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-11-15 00:50:20.250 INFO 15276 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-11-15 00:50:20.269 INFO 15276 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-11-15 00:50:20.269 INFO 15276 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.37]
2020-11-15 00:50:20.546 INFO 15276 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-11-15 00:50:20.547 INFO 15276 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2909 ms
2020-11-15 00:50:20.670 INFO 15276 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-11-15 00:50:21.004 INFO 15276 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-11-15 00:50:21.021 INFO 15276 --- [ restartedMain] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:testdb'
2020-11-15 00:50:21.529 INFO 15276 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-11-15 00:50:21.675 INFO 15276 --- [ task-1] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-11-15 00:50:21.760 WARN 15276 --- [ restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-11-15 00:50:21.800 INFO 15276 --- [ task-1] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.20.Final
2020-11-15 00:50:22.087 INFO 15276 --- [ task-1] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-11-15 00:50:22.410 INFO 15276 --- [ task-1] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2020-11-15 00:50:22.886 INFO 15276 --- [ task-1] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-11-15 00:50:22.901 INFO 15276 --- [ task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-11-15 00:50:23.109 INFO 15276 --- [ task-2] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2020-11-15 00:50:24.016 INFO 15276 --- [ restartedMain] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@5e48e9e9, org.springframework.security.web.context.SecurityContextPersistenceFilter@780cb960, org.springframework.security.web.header.HeaderWriterFilter@2d0b4ae2, org.springframework.security.web.csrf.CsrfFilter@5c7e2a08, org.springframework.security.web.authentication.logout.LogoutFilter@4352ea5, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@634d0e5d, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter@4ad01a34, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter@3c18980d, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@20650474, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@4815273a, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@48596df1, org.springframework.security.web.session.SessionManagementFilter@26232c18, org.springframework.security.web.access.ExceptionTranslationFilter@525ea091, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@707203bf]
2020-11-15 00:50:24.069 WARN 15276 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'pelaajaDemo' defined in fi.haagahelia.course.PelaajaApplication: Unsatisfied dependency expressed through method 'pelaajaDemo' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'model.PelaajaRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2020-11-15 00:50:24.070 INFO 15276 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2020-11-15 00:50:24.071 INFO 15276 --- [ restartedMain] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down'
2020-11-15 00:50:24.077 INFO 15276 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2020-11-15 00:50:24.310 WARN 15276 --- [ restartedMain] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-200]
2020-11-15 00:50:24.311 INFO 15276 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2020-11-15 00:50:24.313 INFO 15276 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2020-11-15 00:50:24.316 INFO 15276 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-11-15 00:50:24.330 INFO 15276 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-11-15 00:50:24.496 ERROR 15276 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method pelaajaDemo in fi.haagahelia.course.PelaajaApplication required a bean of type 'model.PelaajaRepository' that could not be found.
Action:
Consider defining a bean of type 'model.PelaajaRepository' in your configuration.```
请在“跟踪”模式下运行日志,然后进行检查。很难用您提供的一段代码来回答您的查询。
我会建议通过项目(链接给出在下面),然后尝试在您的代码中实现相同的,希望这将解决您的问题。
https://www.programcreek.com/java-api-examples/?code=attacomsian%2fcode-examples%2fcode-examples-master%2fspring-data-jpa%2fjpa-审核%2fsrc%2fmain%2fjava%2fcom%2fattacomsian%2fjpa%2fapplication.Java#
包名:com.sample 现在,当我把所有文件放在一个包下时,它工作得很好。但当我根据功能进行分配时,错误就会发生。我该如何解决这个问题。 按照下面的建议添加basepackages后,我收到的错误为
我是spring的初学者。所以现在我开始学习spring boot并构建这个简单的项目,但是当我运行它时,我得到了这样的错误“Field entityManager in sagala.rest.boot.remade.dao.EmployeeDaoImpl required a bean of type'javax.persistence.entityManager'that count fou
我对整个Spring的生态系统都是陌生的。我一直在学习一些教程,能够创建一个Spring Boot应用程序并执行crud操作。然后我开始把这个项目改成mybatis的标准。 我已经尝试了许多其他类似问题的答案,但到目前为止没有一个是有效的。 下面是问题陈述: 实现类实现为: 我的Mapper类如下所示: 我的Mapper.xml课是: 最后是我的控制器类: 我得到的错误是: 描述: com.cru
描述:com.mongotest.demo.seeder中构造函数的参数0需要类型为“com.mongotest.repositories.studentrepository”的bean,但找不到该bean。 pom.xml