- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我已经解决了这个问题,但找不到发生了什么....尝试@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");
}
}
UserDetailServiceImpl
: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));
}
}
UserServiceImpl
: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);
}
}
CommonBeanConfig
: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 {
}
最佳答案
您正在使用 @Qualifier(value = "userService")
寻找 UserService
:
@Autowired
@Qualifier(value = "userService")
public void setUserService(UserService userService) {
this.userService = userService;
}
但是你没有它,因为你的 UserServiceImpl
被注释为 @Service
而没有提供它的 id。
要将 id 设置为您的 UserServiceImpl
,您需要使用 @Service("userService")
对其进行注释。但是,如果您只有一个 UserService
实现,只需从 setter 中删除 @Qualifier(value = "userService")
,因为它是多余的。
在我看来,这不是唯一需要删除 @Qualifier
的地方。
@Qualifier
注释来选择准确的 bean。如果您只有一个,则无需使用它。
关于java - <method> 中的方法 setUserService 的参数 0 需要找不到类型为 <service> 的 bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42130265/
例如,我有一个父类Author: class Author { String name static hasMany = [ fiction: Book,
代码如下: dojo.query(subNav.navClass).forEach(function(node, index, arr){ if(dojo.style(node, 'd
我有一个带有 Id 和姓名的学生表和一个带有 Id 和 friend Id 的 Friends 表。我想加入这两个表并找到学生的 friend 。 例如,Ashley 的 friend 是 Saman
我通过互联网浏览,但仍未找到问题的答案。应该很容易: class Parent { String name Child child } 当我有一个 child 对象时,如何获得它的 paren
我正在尝试创建一个以 Firebase 作为我的后端的社交应用。现在我正面临如何(在哪里?)找到 friend 功能的问题。 我有每个用户的邮件地址。 我可以访问用户的电话也预订。 在传统的后端中,我
我主要想澄清以下几点: 1。有人告诉我,在 iOS 5 及以下版本中,如果您使用 Game Center 设置多人游戏,则“查找 Facebook 好友”(如与好友争夺战)的功能不是内置的,因此您需要
关于redis docker镜像ENTRYPOINT脚本 docker-entrypoint.sh : #!/bin/sh set -e # first arg is `-f` or `--some-
我是一名优秀的程序员,十分优秀!