EAR情况下的MyBatis CDI类加载器问题 [英] MyBatis CDI class loader issue in case of EAR
问题描述
我有一个EAR,目前只包含一个WAR.我的问题是,如果 mybatis -.... jar 文件位于 web-module.war \ WEB-INF \ lib 下,则一切正常.但是,如果我用Maven进行了一场皮包骨头的战争,并且两个与mybatis相关的罐子位于EAR/lib下,则会出现"没有正确配置SqlSessionFactory生产者."错误.
I have an EAR which at the moment contains only one WAR. My issue is if the mybatis-....jar files locate under web-module.war\WEB-INF\lib then everything works fine. BUT if I create a skinny war with maven and the two mybatis related jars locate under EAR/lib I get a "There are no SqlSessionFactory producers properly configured." error.
我似乎是与类路径有关的问题.
I seems that it is a classpath related issue.
我正计划在我的EAR中添加更多WAR,我想避免将这两个jar放入每个WAR中的情况.
I am planning to add more WAR into my EAR and I would like to avoid the situation to put these two jars into each WARs.
环境:Java 8,Payara Server 4.1.2.172
Environment: Java 8, Payara Server 4.1.2.172
这是我的EAR的结构,但是不起作用
EAR
+-- lib
+ mybatis-3.4.4.jar
+ mybatis-cdi-1.0.0.jar
+-- web-module.war
Web模块包含带有注入的EJB的servlet.该EJB使用myBatis映射器.
The web module contains a servlet with an injected EJB. This EJB uses myBatis mapper.
Servlet
@WebServlet("/echo")
public class EchoServlet extends HttpServlet {
@EJB
private EchoService echoService;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/html");
try (PrintWriter writer = resp.getWriter()) {
writer.println(echoService.echo("lorempisum"));
}
}
}
EJB
@Stateless
public class EchoBean implements EchoService {
@Inject
private AccountDao accountDao;
@Override
public String echo(String text) {
List<String> emails = accountDao.findAll();
return "Hello " + text + "! There are " + emails.size() + " emails in the DB.");
}
}
MyBatis映射器
@Mapper
public interface AccountDao {
@Select("SELECT email FROM dev.account")
List<String> findAll();
}
如果我更改EAR的结构,那么我的项目就可以正常工作.
EAR
+-- lib
+-- web-module.war
+-- WEB-INF
+-- lib
+-- mybatis-3.4.4.jar
+-- mybatis-cdi-1.0.0.jar
我试图将 MANIFEST.MF 文件添加到 ear \ web-module.war \ META-INF 目录中,但没有帮助:>
I tried to add MANIFEST.MF file to ear\web-module.war\META-INF directory with the following content but it did not help:
Class-Path: lib/mybatis-3.4.4.jar lib/mybatis-cdi-1.0.0.jar
我还尝试将 glassfish-web.xml 文件添加到 ear \ web-module.war \ WEB-INF 目录,如
I also tried to add glassfish-web.xml file to ear\web-module.war\WEB-INF directory as described here but it did not help:
<glassfish-web-app>
<class-loader delegate="true" extra-class-path="../lib/mybatis-3.4.4.jar:../lib/mybatis-cdi-1.0.0.jar"/>
</glassfish-web-app>
有什么办法解决这个类路径问题吗?
Any idea how to solve this classpath issue?
推荐答案
这是解决方案:
- 阅读: mybatis-cdi问题跟踪器
- 阅读: payara应用服务器问题跟踪器
- src:我的mybatis-ee-demo应用程序
- src:我的mybatis-web-demo应用程序
- to read: mybatis-cdi issue tracker
- to read: payara app server issue tracker
- src: my mybatis-ee-demo application
- src: my mybatis-web-demo application
这篇关于EAR情况下的MyBatis CDI类加载器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!