Skip to content

When I use QuickTargetSourceCreator getTargetSource to create a prototye TargetSource, the IDEA of evaluate throws the error #35167

Closed as not planned
@chenggwang

Description

@chenggwang

Problems that arise

When I use QuickTargetSourceCreator getTargetSource to create a prototye TargetSource, the IDEA of evaluate throws the error:Method threw 'java.lang.IllegalStateException' exception. Cannot evaluate org.springframework.aop.target.PrototypeTargetSource.toString()

Reproduce use cases

Configuration

@Configuration
public class UserServiceConfig {
    @Bean("!woQu")
    @Scope(value ="prototype")
    public UserService userService(){
        return new UserService();
    }
    //targetSourceCreator
    @Bean
    public QuickTargetSourceCreator targetSourceCreator() {
        return new QuickTargetSourceCreator();
    }
   @Bean
    public ProxyFactoryBean proxyFactoryBean(@Autowired QuickTargetSourceCreator qc) {
        ProxyFactoryBean pfb = new ProxyFactoryBean();
        pfb.setTargetSource(qc.getTargetSource(UserService.class,"!woQu"));
        return pfb;
    }
}

target

public class UserService {
    public void saveUser(String username) {

        System.out.println("Saving user: " + username);
    }
}

start class

@SpringBootApplication
public class MySpringApplication {

	public static void main(String[] args) throws Exception {
		ConfigurableApplicationContext ct = SpringApplication.run(MySpringApplication.class, args);
	}
}

cause of

AbstractBeanFactoryBasedTargetSourceCreator getTargetSource method returns targetSource instance has yet to be completed TargetBeanName Settings, At this point, IDEA or an external tracking tool will call the toString() of targetSource, and toString() will call the getTargetBeanName() method. At this time, the assertion will throw an error

Fix plain

I will submit a fix PR later

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)status: supersededAn issue that has been superseded by another

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions