简体   繁体   English

需要一个找不到类型的 bean

[英]Required a bean of type that could not be found

I made some rest api's in my project.我在我的项目中制作了一些 rest api。 I have their models, repositories, controllers and services.我有他们的模型、存储库、控制器和服务。 They were working fine and My sql server has successfully created all the tables as well.他们工作正常,我的 sql 服务器也成功创建了所有表。

Now I am trying to implement role based authorisation for my apis for which I created a usersauth and a role model.现在我正在尝试为我的 api 实现基于角色的授权,为此我创建了一个usersauth和一个role model。 This is the code that I am following:这是我正在关注的代码:

https://github.com/TechPrimers/spring-security-db-example https://github.com/TechPrimers/spring-security-db-example

Configuration.java:配置.java:

//import statements
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableJpaRepositories(basePackageClasses = UsersAuthRepository.class)
@EnableWebSecurity
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

Application.java:应用。java:

  @SpringBootApplication


 public class Application {

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

When I run my project It gives me this error:当我运行我的项目时,它给了我这个错误:

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

Description:

Field BlankRepository in 

required a bean of type 


that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 
'BlankRepository' in 
 your 
 configuration.

Now this is one of the model that I created previously before implementing authorization.现在这是我之前在实施授权之前创建的 model 之一。 The table is there in sql server as well.该表也在 sql 服务器中。 It is giving this error after implementing authorisation.实施授权后出现此错误。 I have the required repository for this as well.我也有这个所需的存储库。 I am new at spring boot but I think this error has something to do with the我是 spring 启动的新手,但我认为这个错误与

  @EnableJpaRepositories(basePackageClasses = UsersRepository.class)

above in my file.在我的文件中。 Maybe my application is not reading those repos or something.也许我的应用程序没有阅读那些回购或其他东西。 I still dont quite understand the purpose behind this line so can anybody please help me what am i missing?hanks!我仍然不太明白这条线背后的目的,所以任何人都可以帮我看看我错过了什么吗?汉克斯!

add annotatil添加注释

@SpringBootApplication(scanBasePackages={xxx})

or或者

@Repository
public interface UsersRepository extends JpaRepository<Users, Integer> {
    Optional<Users> findByName(String username);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM