今天写了个解析javax.persistence.Table的方法
Java代码:
- /**
- * 通过实体的anno获得Mapping的数据库表名
- * @param clazz 实体类
- * @return
- * @throws Exception
- */
- public static String getTableName(Class<?> clazz) throws Exception {
- if (clazz.isAnnotationPresent(Table.class)) {
- Table table = clazz.getAnnotation(Table.class);
- return table.name();
- } else {
- throw new Exception(clazz.getName() + ” is not Entity Annotation.”);
- }
- }
在启动tomcat的时候报错
Java代码:
- java.lang.ClassNotFoundException: javax.persistence.Table
- at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
- at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
- at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
- at com.faj.util.XSAnnoDeal.getTableName(XSAnnoDeal.java:23)
- at com.faj.util.SqlCreater.<init>(SqlCreater.java:25)
- at com.sucsoft.springmvc.dao.impl.BaseDaoImpl.createSQLAndExcute(BaseDaoImpl.java:31)
- at com.sucsoft.springmvc.dao.impl.BaseDaoImpl.add(BaseDaoImpl.java:39)
- at com.sucsoft.springmvc.service.impl.UserService.createUser(UserService.java:19)
- at com.sucsoft.springmvc.controller.UserController.add(UserController.java:76)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
- at java.lang.reflect.Method.invoke(Method.java:597)
- at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
- at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)
- at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428)
- at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
- at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
- at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:920)
- at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:816)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
- at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:801)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
- at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
- at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
- at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
- at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
- at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
- at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
- at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
- at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
- at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
- at java.lang.Thread.run(Thread.java:619)
找了一个晚上终于找到答案了。
上链接:http://www.blogjava.net/jvict/articles/225646.html
原因是tomcat里面没有javaee-api-5.0-1.jar这个jar包,我用的是javaee 5.0。
原文参考自站长网:http://www.software8.co/wzjs/java/3456.html
今天的文章关于解析javax.persistence.Table报错分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/25147.html