Java 无法在春豆中进行自我注射?
我讲了几个类似的话题: 并编写了以下代码:Java 无法在春豆中进行自我注射?,java,spring,spring-boot,dependency-injection,Java,Spring,Spring Boot,Dependency Injection,我讲了几个类似的话题: 并编写了以下代码: @Service("emailService") public static class EmailService { @Resource(name = "emailService") private EmailService self; @PostConstruct public void initialize() { EmailMessage
@Service("emailService")
public static class EmailService {
@Resource(name = "emailService")
private EmailService self;
@PostConstruct
public void initialize() {
EmailMessage.emailService = self;
}
但它不起作用:
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
16.11.17 15:01:45.692 [main] ERROR o.s.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'emailService': Bean with name 'emailService' has been injected into other beans [csvMappingConfiguration,emailService] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:585)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at ****.Application.main(Application.java:12)
我做错了什么
看起来和我链接的主题一样
P.S.1
SPRING\u BOOT\u VERSION=“1.5.8.发布”
P.S.2
我试过:
public interface SomeService {
public void sendEmail(String from, String subject, String[] to, Map<String, ?> props, String templateFileName) throws Exception;
}
@Service("emailService")
public static class EmailService implements SomeService{
@Resource(name = "emailService")
private SomeService self;
公共接口服务{
public void sendmail(字符串from、字符串subject、字符串[]to、映射道具、字符串templateFileName)引发异常;
}
@服务(“电子邮件服务”)
公共静态类EmailService实现了一些服务{
@资源(name=“emailService”)
私人自助服务;
但它并没有改变任何事情@懒惰对我有用
@Lazy
@Resource(name = "emailService")
private EmailService self;
他们使用类实现的接口。如果你的类EmailService能够实现,比如说一些服务,你可以注入,那就行了。对不起,我没有注意。你的用例是什么?你为什么需要注入自己的bean?你能说出一个用例吗?那么,你考虑过吗?@KernelPanic先生,是的,我考虑过,b但这对我不起作用。可能是因为内部类