我有一個程序從另一個Web服務實際上被稱爲Web服務。我的程序的調用者將輸入(也就是我的程序的輸入)轉換爲JSON,然後調用我的程序,傳遞JSON。我的程序將其轉換爲Java代碼(通過GSON)。請記住,輸入是包含在我的pom中的jar文件。有沒有辦法自動連接一部分輸入?春天 - 在運行時提供@Autowired
什麼我目前所做的就是把@Component
上我想自動裝配的部分,稱爲系統的系統信息:
@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>
我已經成立了一個由一個ApplicationConfig.java:
@Configuration
@ComponentScan(basePackages = "org.mhcd.avatar.model")
public class ApplicationConfig {
}
我把它放在罐子裏,所以它會看到@Component
。我把在XML我的程序:
<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是空的。我在想一定有辦法做到這一點,但我不知道它是什麼。
你想要做的是自動裝載你在webservice中收到的傳輸對象嗎?你爲什麼想這樣做? – reos
[如何在設置新配置後更新所有彈簧對象?](http://stackoverflow.com/questions/36501508/how-can-i-update-all-spring-objects-after-setting-new配置) – nowszy94
@reos是的,就是這樣。我想這樣做,因爲記錄器需要它。 (該記錄器基於log4j 2並寫入數據庫。)我想要@@ Autowired的部分包含大量信息。 – horndinkle