使用 JRebel 从 Eclipse 部署 Web 项目
我正在尝试使用 JRebel 将多模块 Maven 项目从 Eclipse 部署到本地 Tomcat。该项目具有以下结构:
root [packaging: pom]
|
|--- domain [packaging: jar
|
|--- manager [packaging: jar]
|
|--- web [packaging: war]
我在 3 个子模块中的每一个中创建了 src/main/resources/rebel.xml
。我可以从 Eclipse 中将 Web 项目部署到 Tomcat(不使用 JRebel),没有任何问题。
但是,如果我 更改部署以使用 JRebel,我得到以下错误:
SEVERE: Exception sending context initialized event to listener instance
of class com.web.listeners.WebAppListener
java.lang.IllegalArgumentException: Unknown entity: com.model.Role
....
....
Caused by: org.hibernate.MappingException: Unknown entity: com.model.Role
Role
是域项目中的持久性 (JPA/Hibernate) 类,它似乎是触发错误的 WebAppListener
中对其的引用
public class WebAppListener implements ServletContextListener, HttpSessionListener,
HttpSessionAttributeListener {
private RoleManager roleManager;
@Override
public void contextInitialized(ServletContextEvent sce) {
BeanFactory beanFactory = WebApplicationContextUtils.
getRequiredWebApplicationContext(sce.getServletContext());
this.roleManager = beanFactory.getBean(RoleManager.class);
saveIfAbsent("USER", "Normal User");
}
private void saveIfAbsent(String roleName, String roleDescription) {
if (roleManager.getRole(roleName) == null) {
Role role = new Role();
role.setName(roleName);
role.setDescription(roleDescription);
roleManager.saveRole(role);
}
}
}
:看起来像执行此代码时未加载 domain
类,知道如何解决此问题吗?
I'm trying to deploy a multi-module Maven project from Eclipse to a local Tomcat using JRebel. The project has the following structure:
root [packaging: pom]
|
|--- domain [packaging: jar
|
|--- manager [packaging: jar]
|
|--- web [packaging: war]
I've created src/main/resources/rebel.xml
in each of the 3 child modules. I can deploy the web project to Tomcat (without using JRebel) from within Eclipse without any problems.
However, if I change the deployment to use JRebel, I get the following error:
SEVERE: Exception sending context initialized event to listener instance
of class com.web.listeners.WebAppListener
java.lang.IllegalArgumentException: Unknown entity: com.model.Role
....
....
Caused by: org.hibernate.MappingException: Unknown entity: com.model.Role
Role
is a persistent (JPA/Hibernate) class from the domain project and it appears to be the reference to it in WebAppListener
that is triggering the error:
public class WebAppListener implements ServletContextListener, HttpSessionListener,
HttpSessionAttributeListener {
private RoleManager roleManager;
@Override
public void contextInitialized(ServletContextEvent sce) {
BeanFactory beanFactory = WebApplicationContextUtils.
getRequiredWebApplicationContext(sce.getServletContext());
this.roleManager = beanFactory.getBean(RoleManager.class);
saveIfAbsent("USER", "Normal User");
}
private void saveIfAbsent(String roleName, String roleDescription) {
if (roleManager.getRole(roleName) == null) {
Role role = new Role();
role.setName(roleName);
role.setDescription(roleDescription);
roleManager.saveRole(role);
}
}
}
It looks like the domain
classes are not loaded when this code is executed, any idea how to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的反叛档案的内容是什么?它们应该看起来像
如果您使用的是 Maven,您还可以查看相关主题:让 JRebel 与 'mvn tomcat:run' 一起使用
注意:如果rebel.xml还包含对 src/main/resources 的引用,有时它会
混淆了一些框架,如果发生错误,您应该尝试将其从所有rebel.xml 文件中删除。例如,以下conf很常见,但可能并不总是有效:
What is the contents of your rebel files? They should look like
If you're using maven, you can also take a look at a related topic: Getting JRebel to work with 'mvn tomcat:run'
Note: if rebel.xml also contains a reference to src/main/resources, it sometimes
confuses some frameworks and you should try removing it from all rebel.xml files if errors occur. For example, the following conf is quite common, but may not always work:
删除来解决该问题
我通过从域项目中的rebel.xml 文件中 ,如此处所述
I fixed the problem by removing
from the rebel.xml file in the domain project as described here