についてですが、実際には「com.sun.proxy.$Proxy232」タイプのソリューションでした

1. 異常な内容

Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'userService' is expected to be of type 'com.mediacomm.service.impl.UserServiceImpl' but was actually of type 'com.sun.proxy.$Proxy232'
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.checkBeanNotOfRequiredType(DefaultListableBeanFactory.java:1522)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.checkBeanNotOfRequiredType(DefaultListableBeanFactory.java:1529)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1500)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1101)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:583)
	... 69 more

2、解決策

この例外が実際に示していることは、Spring によって作成された userService オブジェクトを参照するためにインジェクションに依存している場合、割り当てのタイプは com.mediacomm.service.impl.UserServiceImpl であると予想されますが、実際には com.sun であるということです。 .proxy.$Proxy232, このプロキシは、一目で jdk の動的プロキシとして見ることができます。ここで引き起こした問題は非常に単純です。つまり、UserServiceImpl が対応するインターフェイスを最初に実装していないため、プロキシ オブジェクトを作成するときと同じインターフェイスを使用します。
1. インターフェースを作成する

public interface UserService {
    
    
    public void saveUser(UserInfo user)throws MyException;
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException;
}

2. インターフェースを実装する

@Service("userService")
public class UserServiceImpl implements UserService {
    
    

3. UserService への依存関係注入のタイプを変更します。

@Controller
@RequestMapping("/user")
public class UserManagerController {
    
    

    @Autowired
    private UserService userService;

おすすめ

転載: blog.csdn.net/weixin_42717117/article/details/119600654