我正在尝试使用Wildfly服务器在Netbeans中运行Web应用程序。我遇到错误
“ jboss.naming.context.java.module.LocalShop.LocalShop.env.ReadBean.dp缺少[jboss.naming.context.java.jboss.datasources.shopstyles]”,我认为这句话 @Resource(lookup =“ java:jboss / datasources / shopstyles”)导致错误。有人可以帮我吗?
包装结构
MANIFEST.MF
我在netbeans中用于Web应用程序的代码:
import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import javax.sql.DataSource;
@Named (value="readBean")
@RequestScoped
public class ReadBean implements Serializable {
@Resource (lookup= "java:jboss/datasources/shopstyles")
private DataSource dp;
public List<Veggie>performRead() throws SQLException{
if(dp == null){
throw new SQLException("Cannot access data pool");
}
List<Veggie>list;
try (Connection con =dp.getConnection()){
if(con == null){
throw new SQLException("Cannot establish connection to database");
}
PreparedStatement ps =con.prepareStatement("select veggie_id,name,price,created_date from veggie");
ResultSet result =ps.executeQuery();
list=new ArrayList<>();
while(result.next()){
Veggie veggie=new Veggie();
veggie.setVeggieID(result.getInt("veggie_id"));
veggie.setName(result.getString("name"));
veggie.setPrice(result.getString("price"));
veggie.setCreated_date(result.getDate("created_date"));
list.add(veggie);
}
}
return list;
}
}
Manifest.mf代码:
清单版本:1.0
Netbeans配置
独立版的一部分