1

我正在尝试使用 JRebel 将多模块 Maven 项目从 Eclipse 部署到本地 Tomcat。该项目具有以下结构:

root [packaging: pom]
|
|--- domain [packaging: jar
|
|--- manager [packaging: jar]
|
|--- web [packaging: war]

我在src/main/resources/rebel.xml3 个子模块中的每一个中都创建了。我可以从 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未加载类,知道如何解决此问题吗?

4

2 回答 2

2

你的叛军文件的内容是什么?他们应该看起来像

<classpath>
    <dir name="/absolute/path/to/projectname/target/classes"></dir>
</classpath>

如果您使用的是 maven,还可以查看相关主题:Getting JRebel to work with 'mvn tomcat:run'

注意:如果 rebel.xml 还包含对 src/main/resources 的引用,它有时会混淆某些框架,如果发生错误,您应该尝试从所有 rebel.xml 文件中删除它。例如,以下 conf 很常见,但可能并不总是有效:

<classpath>
    <dir name="/absolute/path/to/projectname/target/classes"></dir>
    <dir name="/absolute/path/to/projectname/src/main/resources"></dir>
</classpath>
于 2011-07-11T09:31:58.510 回答
0

我通过删除解决了问题

<dir name="/absolute/path/to/projectname/src/main/resources"></dir>

来自域项目中的 rebel.xml 文件,如此处所述

于 2011-07-22T08:56:06.320 回答