我尝试按照本教程
现在我被卡住了。我已经完成了所有的事情,直到听力4.现在我想尝试一下,如果它能起作用的话。 大多数代码只是与其他一些变量名称重复,但当我尝试在我的服务器上部署此程序时,它总是显示我:
引起:org.jboss.weld.exceptions.DeploymentException:WELD-001408:带有限定符@Default的MarketPriceStore类型的不满意依赖项 在注入点[UnbackedAnnotatedField] @Inject private ws.SimpleStockMarketResource.marketPriceStore 在ws.SimpleStockMarketResource.marketPriceStore(SimpleStockMarketResource.java:0)
Class MarketPriceStore出了问题,我不知道是什么......
我的MarketPriceStore代码
@Singleton
@LocalBean
public class MarketPriceStore {
private Map<String,Double> map = new HashMap<String,Double>();
@Inject
Event<MarketpriceChangedEventObject> eventSource;
public void store(String companyName, Double marktPreisNeu){
Double marktPreisAlt = map.get(companyName);
if(!Objects.equals(marktPreisAlt, marktPreisNeu)){
map.put(companyName,marktPreisNeu);
eventSource.fire(new MarketpriceChangedEventObject(companyName, marktPreisNeu));
}
}
public Optional<Double> retrieve(String key){
return Optional.ofNullable(map.get(key));
}
我已经问了一位同事,我们搜索了一下,但没有一个答案令人满意。
我的MarketpriceChangedEventObject代码
public class MarketpriceChangedEventObject {
public final String companyName;
public final Double marktpreis;
public MarketpriceChangedEventObject(String companyName, Double marktpreis){
this.companyName = companyName;
this.marktpreis = marktpreis;
}
}
我的SimpleStockMarketResource代码
public class SimpleStockMarketResourceClient {
private static final String URI = "http://localhost:8080/Entenhausen/ws/SimpleStockMarketResource";
public static void main(String[] args) throws Exception {
try {
String operation = args[0];
String companyName = args[1];
if (operation.equalsIgnoreCase("-get")) {
Double marketPrice = ClientBuilder.newClient()
.target(URI)
.path("{companyName}")
.resolveTemplate("companyName", companyName)
.request()
.get(Double.class);
System.out.println("SUCCESS: Get! => [Market Price=" + marketPrice + "]");
} else if (operation.equalsIgnoreCase("-set")) {
Double marketPrice = Double.valueOf(args[2]);
Response response = ClientBuilder.newClient()
.target(URI)
.path("{companyName}")
.resolveTemplate("companyName", companyName)
.request()
.put(Entity.text(marketPrice));
if (response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) {
System.out.println("SUCCESS: Set!");
} else {
System.err.println("ERROR: Set! => [Status Code=" + response.getStatus() + "]");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}