我经历了这个问题,找不到发生了什么....试图@ComponentScan,试图命名我的服务,似乎没有一个工作。
03:35:05,193 WARN [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext] (ServerService Thread Pool -- 81) Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfiguration': Unsatisfied dependency expressed through method 'setAuthenticationProvider' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'daoAuthenticationProvider' defined in class path resource [com/ipayso/config/SecurityConfiguration.class]: Unsatisfied dependency expressed through method 'daoAuthenticationProvider' parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDetailsService': Unsatisfied dependency expressed through method 'setUserService' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.ipayso.services.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
03:35:05,193 INFO [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] (ServerService Thread Pool -- 81) Closing JPA EntityManagerFactory for persistence unit 'default'
03:35:05,194 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 81) HHH000227: Running hbm2ddl schema export
03:35:05,196 INFO [stdout] (ServerService Thread Pool -- 81) Hibernate: drop table if exists customer cascade
03:35:05,200 INFO [stdout] (ServerService Thread Pool -- 81) Hibernate: drop table if exists private_key cascade
03:35:05,205 INFO [stdout] (ServerService Thread Pool -- 81) Hibernate: drop table if exists public_key cascade
03:35:05,208 INFO [stdout] (ServerService Thread Pool -- 81) Hibernate: drop table if exists user_login cascade
03:35:05,211 INFO [stdout] (ServerService Thread Pool -- 81) Hibernate: drop sequence hibernate_sequence
03:35:05,213 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 81) HHH000230: Schema export complete
03:35:05,223 WARN [org.springframework.boot.SpringApplication] (ServerService Thread Pool -- 81) Error handling failed (Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available)
03:35:05,262 WARN [org.jboss.modules] (ServerService Thread Pool -- 81) Failed to define class org.springframework.boot.autoconfigure.data.rest.SpringBootRepositoryRestConfigurer in Module "deployment.devipayso-1.0.war:main" from Service Module Loader: java.lang.NoClassDefFoundError: Failed to link org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestConfigurer (Module "deployment.devipayso-1.0.war:main" from Service Module Loader): org/springframework/data/rest/webmvc/config/RepositoryRestConfigurerAdapter
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method setUserService in com.ipayso.services.security.UserDetailsServiceImpl required a bean of type 'com.ipayso.services.UserService' that could not be found.
Action:
Consider defining a bean of type 'com.ipayso.services.UserService' in your configuration.
package com.project.config
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
private AuthenticationProvider authenticationProvider;
@Autowired
@Qualifier("daoAuthenticationProvider")
public void setAuthenticationProvider(AuthenticationProvider authenticationProvider) {
this.authenticationProvider = authenticationProvider;
}
@Bean
public PasswordEncoder passwordEncoder(StrongPasswordEncryptor passwordEncryptor){
PasswordEncoder passwordEncoder = new PasswordEncoder();
passwordEncoder.setPasswordEncryptor(passwordEncryptor);
return passwordEncoder;
}
@Bean
public DaoAuthenticationProvider daoAuthenticationProvider(PasswordEncoder passwordEncoder, UserDetailsService userDetailsService){
DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
daoAuthenticationProvider.setPasswordEncoder(passwordEncoder);
daoAuthenticationProvider.setUserDetailsService(userDetailsService);
return daoAuthenticationProvider;
}
@Autowired
public void configureAuthManager(AuthenticationManagerBuilder authenticationManagerBuilder){
authenticationManagerBuilder.authenticationProvider(authenticationProvider);
}
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.authorizeRequests().antMatchers("/", "/home", "/login", "/signup").permitAll()
.and()
.formLogin()
.loginPage("/login")
.failureUrl("/login-error")
.and()
.logout()
.logoutSuccessUrl("/home");
}
}
package com.project.service.security
@Service("userDetailsService")
public class UserDetailsServiceImpl implements UserDetailsService {
private UserService userService;
private Converter<User, UserDetails> userUserDetailsConverter;
@Autowired
@Qualifier(value = "userService")
public void setUserService(UserService userService) {
this.userService = userService;
}
@Autowired
@Qualifier(value = "userToUserDetails")
public void setUserUserDetailsConverter(Converter<User, UserDetails> userUserDetailsConverter) {
this.userUserDetailsConverter = userUserDetailsConverter;
}
@Override
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
return userUserDetailsConverter.convert(userService.findByEmail(email));
}
}
package com.project.service
@Service
@Profile("springdatajpa")
public class UserServiceImpl implements UserService{
private UserRepository userRepository;
@Autowired
public void setUserRepository(UserRepository userRepository) {
this.userRepository = userRepository;
}
private EncryptionService encryptionService;
@Autowired
public void setEncryptionService(EncryptionService encryptionService) {
this.encryptionService = encryptionService;
}
@Override
public List<?> listAll() {
List<User> users = new ArrayList<>();
userRepository.findAll().forEach(users::add); //fun with Java 8
return users;
}
@Override
public User getById(Integer id) {
return userRepository.findOne(id);
}
@Override
public User saveOrUpdate(User domainObject) {
if(domainObject.getPassword() != null){
domainObject.setEncryptedPassword(encryptionService.encryptString(domainObject.getPassword()));
}
return userRepository.save(domainObject);
}
@Override
@Transactional
public void delete(Integer id) {
userRepository.delete(id);
}
@Override
public User findByEmail(String email) {
return userRepository.findByEmail(email);
}
}
package com.project.config
@Configuration
public class CommonBeanConfig {
@Bean
public StrongPasswordEncryptor strongEncryptor(){
StrongPasswordEncryptor encryptor = new StrongPasswordEncryptor();
return encryptor;
}
}
package com.project
@SpringBootApplication
public class App extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(applicationClass, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(applicationClass);
}
private static Class<App> applicationClass = App.class;
}
package com.project.config
@Configuration
@EnableAutoConfiguration
@EntityScan(basePackages = {"com.ipayso.model"})
@EnableJpaRepositories(basePackages = {"com.ipayso.repositories"})
@EnableTransactionManagement
public class RepositoryConfiguration {
}
如果您在运行junit测试时收到这个错误,那么您可能需要为该对象添加模拟
@MockBean ClassError class Error;
在具有@SpringBootConfiguration
注释的类中
您正在此处查找< code > @ Qualifier(value = " UserService ")的< code>UserService:
@Autowired
@Qualifier(value = "userService")
public void setUserService(UserService userService) {
this.userService = userService;
}
但是你没有它,因为你的UserServiceImpl
注释为@Service
而没有提供它的id。
要为您的UserServiceImpl
设置id,您需要使用@Service(“userService”)
。但是,如果您有一个UserService
实现,只需从setter中删除@Qualifier(value=“UserService”)
,因为它是冗余的。
在我看来,这不是唯一一个你必须删除@Qualifier
的地方。
@Qualifier
如果您有许多相同类型的bean,则需要注释来选择精确的bean。如果你有一个,你不需要使用它。
我想有一个SSO CAS认证,我已经按照Bealdung的教程(https://www.baeldung.com/spring-security-cas-sso第4部分)的说明,但当我作为Spring启动应用程序运行时,我有这个错误 SecurityConfig中构造函数的参数0需要找不到类型为“org.springframework.security.cas.authentication.Cas
我正在创建一个,其中任何客户端都可以提交请求,这些请求可以是、、、。 但是在创建这个应用程序时,我遇到了以下错误: 我的应用程序的结构是: 我尝试用、、注释,但仍然得到相同的错误。 我甚至从这些答案中尝试了解决方案: (1)构造函数的参数0需要一个类型为'java.lang.String'的bean,但找不到该bean 但我仍然无法解决我的问题。
在使用Hibernate作为ORM创建将对象保存在DB中的服务时,我无法启动应用程序。 当我启动SpringBoot应用程序时,我会得到以下错误消息。
我有两个项目: null 提前感谢您的帮助。
我正在用spring Boot2.x应用程序处理spring batch,实际上它的现有代码我是从Git签出的。在运行应用程序时,它失败了,因为下面的错误只对我来说,同样的代码是为其他人工作的。 我已经检查了下面 null
我是Spring启动的新手,我无法从我的Spring启动书中获取示例来工作。这是代码 描述: Thomas中构造函数的参数0。ChapterController需要一个 行动: 考虑定义一个“Thomas”类型的bean。在你的配置中。 章节.java 第章存储库.java LoadDatabase.Java 章节控制器.java ThomasSpringApplication.java