java Spring在运行时提供@Autowired
我有一个被称为web服务的程序,实际上是来自另一个web服务。我的程序的调用者将输入(也就是我的程序的输入)转换为JSON,然后调用我的程序,将JSON传入。我的程序(通过GSON)将其转换为Java代码。请记住,输入是在我的pom中包含的jar文件中。有没有办法自动连接输入的一部分
到目前为止,我所做的是将@Component
放在我想要自动连线的部分上,称为SystemInfo:
@Component
public class SystemInfo {
protected String GUID;
protected String EntityID;
protected Double EpisodeNumber;
protected Double ErrorCode;
protected String ErrorMesg;
protected String Facility;
protected String NamespaceName;
protected String OptionId;
protected String OptionStaffId;
protected String OptionUserId;
protected String ParentNamespace;
protected String ServerName;
protected String SystemCode;
protected String WarName;
protected String ScriptName;
/**
* @return the gUID
*/
public String getGUID() {
return GUID;
}
<other setters and getters>
我已经设置了一个应用程序配置。java,包括:
@Configuration
@ComponentScan(basePackages = "org.mhcd.avatar.model")
public class ApplicationConfig {
}
我把它放进罐子里,这样它就能看到^{
<bean id="systemInfo"
class="org.mhcd.avatar.model.domainLayer.SystemInfo"
autowire="byType" autowire-candidate="true">
</bean>
然后,我在我的程序中加入:
@Autowired
private ApplicationContext context;
及
GenericApplicationContext ctx = new GenericApplicationContext(context);
ctx.refresh();
将JSON转换为Java对象后的刷新。我把@Autowired
放在我的DAO对象中的SystemInfo前面,在调试中逐步检查我的DAO,SystemInfo为空。我在想一定有办法做到这一点,但我不知道是什么
共 (0) 个答案