Java Spring Autowire byName、属性名称与bean xml id的名称不匹配
我对BeanXML在设置其构造函数参数时的作用感到非常困惑。我目前正在使用以下bean配置:Java Spring Autowire byName、属性名称与bean xml id的名称不匹配,java,spring,spring-framework-beans,Java,Spring,Spring Framework Beans,我对BeanXML在设置其构造函数参数时的作用感到非常困惑。我目前正在使用以下bean配置: <bean id="streamingService" class="com.christien.autowiring.StreamingService" autowire="byName"> <property name="serviceName" value="Twit
<bean id="streamingService" class="com.christien.autowiring.StreamingService" autowire="byName">
<property name="serviceName" value="Twitch"></property>
</bean>
<!-- id must be spelled the same as variable in StreamingService class in order to work -->
<bean id="screenRecord" class="com.christien.autowiring.ScreenRecord" />
问题是?我不知道这个项目中存在哪个问题?当I'd与属性名不匹配时,autowire如何知道如何连接到该特定类?它与属性名匹配,与字段名不匹配。但字段的名称不是属性的名称。属性名是从属于字段的getter/setter派生的。您有一个
设置屏幕记录
,因此有一个名为屏幕记录
的可写属性。它在内部设置一个名为this.screenRecorderX的字段并不重要。外部有一个名为screenRecorder
的属性。这是由指定的。
public class StreamingService {
private ScreenRecord screenRecorderX;
private String serviceName;
public ScreenRecord getScreenRecorder() {
return screenRecorderX;
}
public void setScreenRecord(ScreenRecord creenRecord) {
this.screenRecorderX = creenRecord;
}
public String getServiceName() {
return serviceName;
}
public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}
public void startStream() {
System.out.println("Stream Starting in 3, 2, 1 ...");
screenRecorderX.beginRecording();
}
public void endStream() {
System.out.println("Stream ending now...");
screenRecorderX.stopRecording();
}
}
How does this work if there is no property named "screenRecord" in the StreamingService.java, unless I am completely misunderstanding what its supposed to be looking up for reference. Thanks!