首页 > 解决方案 > 当我使用 Dockerfile 运行 UniTime 时,它​​会不断产生错误吗?

问题描述

我需要在 Docker 上使用 UniTime,但它不能正常工作,当我运行它时我不断收到错误消息。

我得到的错误:

ERROR  TaskExecutorService -> Failed to check for tasks: The session factory has not been initialized (or an error occured during initialization)
java.lang.RuntimeException: The session factory has not been initialized (or an error occured during initialization)
    at org.unitime.timetable.model.base._BaseRootDAO.getSessionFactory(_BaseRootDAO.java:111)
    at org.unitime.timetable.model.base._BaseRootDAO.getSession(_BaseRootDAO.java:151)
    at org.unitime.timetable.model.base._BaseRootDAO.createNewSession(_BaseRootDAO.java:141)
    at org.unitime.timetable.server.script.TaskExecutorService.checkForQueuedTasks(TaskExecutorService.java:67)
    at org.unitime.timetable.server.script.TaskExecutorService$TaskExecutor.run(TaskExecutorService.java:162)

Dockerfile:

FROM tomcat:8

EXPOSE 8080

RUN apt-get update && \
    apt-get install -y apt-utils && \
    apt-get install -y default-mysql-server
ENV JAVA_OPTS="-Djava.awt.headless=true -Xmx2g -XX:+UseConcMarkSweepGC"
ENV TOMCAT8_GROUP=tomcat8
ENV TOMCAT8_USER=tomcat8
RUN wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.38/mysql-connector-java-5.1.38.jar && \
    cp mysql-connector-java-5.1.38.jar /usr/local/tomcat/lib/ && \
    wget https://github.com/UniTime/unitime/releases/download/v4.4.140/unitime-4.4_bld140.zip && \
    unzip unitime-4.4_bld140.zip -d unitime && \
    /etc/init.d/mysql start && \
    mysql -uroot -f <unitime/doc/mysql/schema.sql && \
    mysql -uroot -f <unitime/doc/mysql/schema.sql && \
    mysql -utimetable -punitime <unitime/doc/mysql/blank-data.sql && \
    mkdir /usr/local/tomcat/data && \
    useradd tomcat && \
    chown tomcat /usr/local/tomcat/data && \
    cp unitime/web/UniTime.war /usr/local/tomcat/webapps

标签: dockerdockerfile

解决方案


如果您仍在为此寻求帮助。以下是我必须在 UniTime 文件中进行的一些更改才能使用 Docker Deploy。一些 lib 更新特定于 Java 8。

  1. 取消注释 UniTime pom.xml https://github.com/UniTime/unitime/blob/master/pom.xml#L275-L282中的 mysql 连接部分 将 pom 的 mysql.version 更新为您正在使用的版本。

  2. 在 UniTime .project 添加 com.gwtplugins.gwt.eclipse 引用

        <buildCommand>
            <name>com.gwtplugins.gdt.eclipse.core.webAppProjectValidator</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>com.gwtplugins.gwt.eclipse.core.gwtProjectValidator</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
...
        <nature>com.gwtplugins.gwt.eclipse.core.gwtNature</nature>
    </natures>
...
  1. 在 UniTime Documentation/Database/MySQL/schema.sql 中找到与 localhost (127..?) 等效的 docker 或扩展时间表用户范围(用于测试)。
...
drop user timetable@localhost;
drop user IF EXISTS timetable@localhost;

create user timetable@localhost identified by 'unitime';
/* for Docker */
create user timetable@'%' identified by 'unitime';

grant all on timetable.* to timetable@localhost;
/* for Docker */
grant all on timetable.* to timetable@'%';
...
  1. 在 UniTime JavaSource/hibernate.cfg.xml 添加额外的休眠参数
...

   <property name="connection.url">jdbc:mysql://database:3306/timetable?allowPublicKeyRetrieval=TRUE</property>
...
    <!-- for Java 8-11 TSLv1.2 SSL 3 -->
    <property name="hibernate.connection.verifyServerCertificate">false</property>
    <property name="hibernate.connection.requireSSL">false</property>
    <property name="hibernate.connection.useSSL">false</property>
    <!-- End of MySQL Configuration -->
...
  1. 我使用 docker-compose.yml 文件来设置 tomcat 和 docker 配置。

推荐阅读