所选项目没有更新,但我遇到异常,我们非常感谢您的帮助。
异常追踪:
viewOrders....
Jul 05, 2017 3:40:12 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/Camel1Orderfulfillment] threw exception [Request processing failed; nested exception is org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly] with root cause
javax.persistence.RollbackException: Transaction marked as rollbackOnly
at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:74)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:515)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:757)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:478)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:272)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy269.getOrderDetails(Unknown Source)
at com.pluralsight.orderfulfillment.order.OrderController.viewOrders(OrderController.java:102)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
服务:
public interface OrderService {
List<Order> getOrderDetails();
}
ServiceImpl :(仅使用getter)
@Override
public List<Order> getOrderDetails() {
List<Order> orders = new ArrayList<Order>();
try {
for (Iterator<OrderEntity> iterator = orderRepository.findAll().iterator(); iterator.hasNext();) {
OrderEntity entity = iterator.next();
CustomerEntity customerEntity = entity.getCustomer();
Customer customer = new Customer(customerEntity.getId(), customerEntity.getFirstName(),
customerEntity.getLastName(), customerEntity.getEmail());
orders.add(new Order(entity.getId(), customer, entity.getOrderNumber(), entity.getTimeOrderPlaced(),
entity.getLastUpdate(), OrderStatus.getOrderStatusByCode(entity.getStatus()).getDescription()));
}
} catch (Exception e) {
log.error("An error occurred while retrieving all orders: " + e.getMessage(), e);
}
return orders;
}
控制器:
@Controller
public class OrderController {
@Inject
private OrderService orderService;
@RequestMapping(value = "/viewOrders", method = RequestMethod.GET)
public String viewOrders(Model model) {
model.addAttribute("orders", orderService.getOrderDetails());
return "viewOrders";
}
}
的build.gradle:
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'war'
apply plugin: "eclipse"
group = 'com.pluralsight.camel'
version = '1.0-SNAPSHOT'
description = """"""
sourceCompatibility = 1.7
targetCompatibility = 1.7
repositories {
maven { url "http://central.maven.org/maven2/" }
}
dependencies {
compile(group: 'org.springframework', name: 'spring-core', version:'4.0.4.RELEASE') {
exclude(module: 'commons-logging')
}
compile group: 'org.springframework', name: 'spring-aop', version:'4.0.4.RELEASE'
compile group: 'org.springframework', name: 'spring-context', version:'4.0.4.RELEASE'
compile group: 'org.springframework', name: 'spring-tx', version:'4.0.4.RELEASE'
compile group: 'org.springframework', name: 'spring-aspects', version:'4.0.4.RELEASE'
compile group: 'org.springframework', name: 'spring-web', version:'4.0.4.RELEASE'
compile group: 'org.springframework', name: 'spring-webmvc', version:'4.0.4.RELEASE'
compile group: 'org.springframework', name: 'spring-jdbc', version:'4.0.4.RELEASE'
compile(group: 'org.springframework.data', name: 'spring-data-jpa', version:'1.5.2.RELEASE') {
exclude(module: 'spring-aop')
}
compile group: 'javax.validation', name: 'validation-api', version:'1.0.0.GA'
compile group: 'org.hibernate', name: 'hibernate-validator', version:'4.3.1.Final'
compile group: 'org.hibernate', name: 'hibernate-core', version:'4.3.5.Final'
compile group: 'org.hibernate', name: 'hibernate-entitymanager', version:'4.3.5.Final'
compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version:'1.0.0.Final'
compile group: 'org.springframework', name: 'spring-orm', version:'4.0.4.RELEASE'
compile group: 'org.slf4j', name: 'jcl-over-slf4j', version:'1.7.6'
compile group: 'org.slf4j', name: 'slf4j-api', version:'1.7.6'
compile group: 'org.slf4j', name: 'slf4j-log4j12', version:'1.7.6'
compile group: 'log4j', name: 'log4j', version:'1.2.14'
compile group: 'org.aspectj', name: 'aspectjrt', version:'1.7.4'
compile group: 'cglib', name: 'cglib-nodep', version:'2.2'
compile group: 'javax.inject', name: 'javax.inject', version:'1'
compile group: 'postgresql', name: 'postgresql', version:'9.1-901.jdbc4'
compile group: 'commons-dbcp', name: 'commons-dbcp', version:'1.4'
compile group: 'jstl', name: 'jstl', version:'1.2'
compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version:'1.9.9'
compile group: 'org.apache.tiles', name: 'tiles-jsp', version:'2.2.2'
compile group: 'org.apache.tiles', name: 'tiles-el', version:'2.2.2'
compile group: 'org.apache.commons', name: 'commons-lang3', version:'3.3.2'
compile group: 'net.sf.opencsv', name: 'opencsv', version:'2.3'
compile group: 'org.apache.camel', name: 'camel-spring', version:'2.13.2'
compile group: 'org.apache.camel', name: 'camel-spring-javaconfig', version:'2.13.2'
compile group: 'org.apache.camel', name: 'camel-test-spring', version:'2.13.2'
testCompile group: 'org.springframework', name: 'spring-test', version:'4.0.4.RELEASE'
testCompile(group: 'junit', name: 'junit-dep', version:'4.10') {
exclude(module: 'hamcrest-core')
}
testCompile group: 'org.hamcrest', name: 'hamcrest-library', version:'1.3'
testCompile group: 'org.mockito', name: 'mockito-core', version:'1.9.0'
compile(group: 'javax.servlet', name: 'javax.servlet-api', version:'3.0.1') {
/* This dependency was originally in the Maven provided scope, but the project was not of type war.
This behavior is not yet supported by Gradle, so this dependency has been converted to a compile dependency.
Please review and delete this closure when resolved. */
}
compile(group: 'javax.servlet.jsp', name: 'jsp-api', version:'2.2') {
/* This dependency was originally in the Maven provided scope, but the project was not of type war.
This behavior is not yet supported by Gradle, so this dependency has been converted to a compile dependency.
Please review and delete this closure when resolved. */
}
}