我正在创建一个简单的Web应用程序,并决定使用Spring JdbcTemplate类。但现在我遇到了NoClassDefFoundError:org / springframework / jdbc / core / RowMapper。
根据堆栈跟踪,第32行的ControllerServlet出现问题。这是:
collection = ET.fromstring(input)
lst = collection.findall('movie')
print ('Movie count:', len(lst))
for item in lst:
print ('Movie Title', item.get("title"))
movieTypes = item.findall('type')
for movieType in movieTypes:
print ('Type', movieType.text)
print ('Format', item.find('format').text)
print ('Year',item.find('year').text)
print ""
错误可能是什么原因?我该怎么做才能解决它?
productDAOImpl = new ProductDAOImpl(dataSource);
ControllerServlet.java
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)
ProductDAOImpl.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);
}