我正在创建一个简单的Web应用程序,并决定使用Spring JdbcTemplate类。但是现在我遇到了noClassDefFounderror:org/springframework/jdbc/core/rowmapper。
productDAOImpl = new ProductDAOImpl(dataSource);
Context Path:/webstore_war_exploded
Servlet Path:/ControllerServlet
Path Info:null
Query String:null
Stack Trace
java.lang.NoClassDefFoundError: org/springframework/jdbc/core/RowMapper
com.ncproject.webstore.controller.ControllerServlet.init(ControllerServlet.java:32)
javax.servlet.GenericServlet.init(GenericServlet.java:244)
io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:117)
org.wildfly.extension.undertow.security.RunAsLifecycleInterceptor.init(RunAsLifecycleInterceptor.java:78)
io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:103)
io.undertow.servlet.core.ManagedServlet$DefaultInstanceStrategy.start(ManagedServlet.java:250)
io.undertow.servlet.core.ManagedServlet.getServlet(ManagedServlet.java:171)
io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:84)
io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:745)
ControllerServlet.java
@WebServlet("/ControllerServlet")
public class ControllerServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private ProductDAOImpl productDAOImpl;
@Resource(lookup = "java:/PostgresNC")
private DataSource dataSource;
@Override
public void init() throws ServletException {
super.init();
try {
productDAOImpl = new ProductDAOImpl(dataSource);
} catch (Exception exc) {
throw new ServletException(exc);
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
String theCommand = request.getParameter("command");
if (theCommand == null) {
theCommand = "PRODUCT_LIST";
}
switch (theCommand) {
case "PRODUCT_LIST":
listProducts(request, response);
break;
case "ADD_UPDATE":
addOrUpdateProduct(request, response);
break;
default:
listProducts(request, response);
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void listProducts(HttpServletRequest request, HttpServletResponse response) throws Exception {
List<Product> products = productDAOImpl.getAllProducts();
request.setAttribute("PRODUCT_LIST", products);
RequestDispatcher dispatcher = request.getRequestDispatcher("/list-products.jsp");
dispatcher.forward(request, response);
}
private void addOrUpdateProduct(HttpServletRequest request, HttpServletResponse response) throws Exception {
// read product from the form
String idString = request.getParameter("productId");
String category = request.getParameter("category");
String description = request.getParameter("description");
String productName = request.getParameter("productName");
String price = request.getParameter("price");
BigDecimal priceBigDecimal = new BigDecimal(price);
String brand = request.getParameter("brand");
try {
int id = Integer.parseInt(idString.trim());
int numCategory = Integer.parseInt(category);
if(idString != null && category != null) {
Product theProduct = new Product(id, numCategory, description, productName, priceBigDecimal, brand);
// add the product to the database
productDAOImpl.saveOrUpdate(theProduct);
}
}
catch(NumberFormatException nfe) {
nfe.printStackTrace();
}
listProducts(request, response);
}
ProductDaoImpl.java
public class ProductDAOImpl implements ProductDAO {
private JdbcTemplate jdbcTemplate;
//private DataSource dataSource;
public ProductDAOImpl(DataSource dataSource) {
jdbcTemplate = new JdbcTemplate(dataSource);
}
@Override
public List<Product> getAllProducts() {
String sql = "SELECT * FROM products ORDER BY prod_id\n" +
"ASC";
List<Product> productList = jdbcTemplate.query(sql, new RowMapper<Product>() {
@Override
public Product mapRow(ResultSet resultSet, int rowNum) throws SQLException {
Product theProduct = new Product();
theProduct.setProd_id(resultSet.getInt("prod_id"));
theProduct.setCategory(resultSet.getInt("category"));
theProduct.setDescription(resultSet.getString("description"));
theProduct.setProductName(resultSet.getString("productName"));
theProduct.setPrice(resultSet.getBigDecimal("price"));
theProduct.setBrand("brand");
return theProduct;
}
});
return productList;
}
@Override
public void saveOrUpdate(Product newProduct) {
if (newProduct.getProd_id() > 0) {
// update
String sql = "UPDATE products "
+ "SET category=?, description=?, prod_name=?, price=?, brand=? "
+ "WHERE prod_id=?";
jdbcTemplate.update(sql, newProduct.getCategory(), newProduct.getDescription(),
newProduct.getProductName(), newProduct.getPrice(), newProduct.getBrand());
} else {
// insert
String sql = "INSERT INTO products (prod_id, category, description, prod_name, price, brand) "
+ "VALUES (?, ?, ?, ?, ?, ?)";
jdbcTemplate.update(sql, newProduct.getProd_id(), newProduct.getCategory(), newProduct.getDescription(),
newProduct.getProductName(), newProduct.getPrice(), newProduct.getBrand());
}
} }
所需的JAR文件不可用,所以您需要做的是将其放在类路径
上。您可以选择将相应的JAR文件添加到类路径中,也可以从这里下载JAR文件。
一个关于同一主题的类似问题,供您参考的是这里和这里。
问题内容: 我正在使用spring进行一些测试,但出现此错误: 我安装的JAR是:spring-test-2.5.6.jar 除此之外,我还需要另一个罐子吗? 谢谢 问题答案: 您还需要通过查看包装,通常可以告诉您缺少了哪些罐子。在此org.springframework.core。*都在核心jar文件中。
问题内容: 我正在尝试使用Spring Boot编写一个简单的RESTful服务。但是,有一条错误消息我无法解决。我一直在研究, 看来这是SpringBoot版本之间的冲突,但是我不确定如何摆脱它。 我有这个SpringBootApp: Associated with this pom.xml: Looks fine for me, but I am getting this error: 问题答
问题内容: 我正在尝试使用Spring Boot编写一个简单的RESTful服务。但是,有一条错误消息我无法解决。我一直在研究,看来这是SpringBoot版本之间的冲突,但是我不确定如何摆脱它。 我有这个SpringBootApp: 与此pom.xml相关联: 对我来说看起来不错,但出现此错误: 问题答案: 转到Spring boot Initialzr站点,然后选择Web stack作为依赖项
我正在学习使用apache wicket进行开发,并且尝试将Spring集成在一起
问题内容: 我正在尝试运行此处给出的示例图块示例。 以下是我的POM.xml: 当我尝试运行示例时,抛出以下错误: 任何想法? 为此,我花了30分钟的时间进行谷歌搜索,但找不到可能的解决方案。 请帮我… 问题答案: 您已经包括了对SLF4J API的依赖关系,这是您在应用程序中用于日志记录的内容,但是您还必须包括一个实现实际日志记录功能的实现。 例如,要通过Log4J登录,您可以添加以下依赖项:
applicationContext.xml 如果有人能指出我代码中的错误,真的很感激。