我有一个EAR,目前只包含一个WAR。我的问题是如果 mybatis -.... jar 文件位于 web-module.war \ WEB-INF \ lib 下,那么一切正常。但是,如果我用maven创建一个瘦的战争,并且两个mybatis相关的jar位于EAR / lib下,我得到一个" 没有正确配置的SqlSessionFactory生成器。"错误。
我认为这是与类路径相关的问题。
我打算在我的EAR中添加更多WAR,我想避免将这两个罐放入每个WAR中的情况。
环境: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映射器。
的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
@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 目录中,但它没有帮助:
Class-Path: lib/mybatis-3.4.4.jar lib/mybatis-cdi-1.0.0.jar
我还尝试将 glassfish-web.xml 文件添加到 ear \ web-module.war \ WEB-INF 目录中,如here所述,但它没有帮助:
<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>
知道如何解决这个类路径问题吗?
答案 0 :(得分:-1)
我不确切地记得这是否是我们最终解决这个问题的原因,但是:解压缩你的EAR组件(用于战争的简单文件夹和耳内档案中的ejbs)可能有所帮助。
以下是Maven的配置:
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<applicationName>myApp</applicationName>
<version>6</version>
<filtering>true</filtering>
<initializeInOrder>true</initializeInOrder>
<defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
<unpackTypes>war,ejb</unpackTypes>
<modules>
<ejbModule>
<groupId>com.example</groupId>
<artifactId>myapp-ejb</artifactId>
<bundleFileName>myapp-ejb.jar</bundleFileName>
</ejbModule>
<webModule>
<groupId>com.example</groupId>
<artifactId>myapp-rest</artifactId>
<contextRoot>/myapp</contextRoot>
<bundleFileName>myapp.war</bundleFileName>
</webModule>
</modules>
</configuration>
</plugin>
答案 1 :(得分:-1)