---
title: "Alfresco安装后启动异常处理"
author: "IThead"
date: "2012-10-12T14:29:39Z"
tags: []
categories: ["企业架构"]
slug: "alfresco"
draft: false
lastmod: "2012-10-12T14:29:39Z"
id: 1697120
url: "https://ithead.iteye.com/blog/1697120"
---

当出现下面这些出错信息时，只要知道其出错的原理，就很容易解决它。
⑴ org.alfresco.error.AlfrescoRuntimeException
不能直接在alfresco/tomcat/bin中运行startup.bat启动Tomcat，会报错：
00:31:34,687 ERROR  Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean wit
h name 'dictionaryRepositoryBootstrap' defined in class path resource : Invocation of init method failed; nested exception i
s org.alfresco.error.AlfrescoRuntimeException: Failure during rollback: org.alfr
esco.repo.dictionary.DictionaryRepositoryBootstrap$1@2589c3
Caused by:
org.alfresco.error.AlfrescoRuntimeException : Failure during rollback: org.alfres
co.repo.dictionary. DictionaryRepositoryBootstrap $1@2589c3      
 
出错是因为在alfresco/tomcat/bin中运行startup.bat启动Tomcat，找不到相应的HSQL database的初始化信息，可以参考下面的 ⑶仔细思考一下。
 
注1： 思考之后，你也许会尝试把alfresco/alf_data/hsql_data这个文件夹放到alfresco/tomcat/bin目录中，然后再次运行startup.bat启动Tomcat，你可以看一下运行结果会怎样，这会帮助你理解alfresco初始化）。
 
注2： 如果你使用的是mysql数据库，而mysql数据库没有运行mysqld启动的话，也会报上面错误。
 
⑵ 在alfresco.bat中这样几行字：
rem The following options are only required for Sun JVMs prior to 1.5 update 8
set JAVA_OPTS=%JAVA_OPTS% -XX:CompileCommand=exclude,org/apache/lucene/index/IndexReader$1,doBody -XX:CompileCommand=exclude,org/alfresco/repo/search/impl/lucene/index/IndexInfo$Merger,mergeIndexes -XX:CompileCommand=exclude,org/alfresco/repo/search/impl/lucene/index/IndexInfo$Merger,mergeDeletions
注意上面绿色信息，如果你的JDK版本过低的话，上面这一行字是必须的。
 
注： java -version 可以查看JDK版本
我本机版本查看如下：
java version "1.5.0_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode, sharing)
J2SE Development Kit 1.5 update 5
如上，说明JDK版本是J2SE Development Kit 1.5 update 5，那么上面alfresco.bat中的几行字按照上面绿色注释也是必须加的。
 
不过我尝试去掉上面alfresco.bat中的几行字，并没有报错，估计1.5 update 5到1.5 update 7中alfresco.bat中的几行字也都是可以去掉的。
 
要想去掉上面alfresco.bat中的几行字，必须下载JDK的相应版本，下载地址为：http://java.sun.com/products/archive/
 
⑶ alfresco/alf_data 下面有一个hsql_data文件夹，存放的是一些HSQL database的初始化信息，如果删除，也会报 ⑴中的错
hsql_data 下面有两个文件
alfresco.properties ：配置HSQL数据库的一些初始化参数
alfresco.script ：创建HSQL数据库用户的sql语句，默认创建两个HSQL用户（如下）。
CREATE USER SA PASSWORD ""
CREATE USER ALFRESCO PASSWORD "ALFRESCO"
 
注： 启动alfresco时，如果HSQL数据库被更改，alfresco.properties文件会被更新，文件中的modified=no更新为modified=yes
 
⑷ 清空初始化信息和缓存（呵呵，当你进入http://localhost:8080/alfresco/进行了一些CRUD的操作之后就不要随便清空了，这会重新初始化你的HSQL数据库）。
比较重要的一点是在出错之后如果使用alf_start.bat重新启动alfresco，最好要删除清空文件夹：alfresco/alf_data（见注1），alfresco/tomcat/temp，否则很可能会报错。
 
注1： 使用alf_start.bat重新启动alfresco后，会在alfresco/alf_data下生成4个文件夹：lucene-indexes/contentstore.deleted/contentstore/audit.contentstore
 
注2： 其中alfresco/alf_data/hsql_data文件夹千万不能删除，原因如 ⑶所述
 
注3： 另外，为彻底一点，你也可以清空alfresco/tomcat/work（tomcat下的/缓存文件夹）。
 
⑸ 如果出现下面错误：
Exception in thread " HSQLDB Timer @3de2df" java.lang.NullPointerException
        at org.hsqldb.lib.HsqlTimer.nextTask(Unknown Source)
        at org.hsqldb.lib.HsqlTimer$TaskRunner.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:595)
可能是alfresco关闭时不正常，可以再次运行alfresco/alf_stop.bat进行关闭。
 
⑹ 如果删除alfresco/bin下的Win32NetBIOS.dll（我本机是32位XP系统，64位的对应Win32NetBIOSx64.dll），启动alfresco/alf_start.bat时会出现下面错误：
10:38:11,046 INFO   Found 0 module(s).
java.lang.UnsatisfiedLinkError: no Win32NetBIOS in java.library.path
 
出现这种错误是因为删除了Win32NetBIOS.dll，查看alfresco/alfresco.bat，可以看到：
set PATH=%ALF_HOME%bin;%PATH%
在启动alfresco/alfresco.bat时java.library.path也会使用PATH中的路径（alfresco/bin）去寻找相应的Win32NetBIOS.dll，如果找不到，就会报上面的错误。
 
注1： 新建一个JAVA类，在其中调用System.out.println(System.getProperty("java.library.path"));
可以得到java.library.path的值。
下面是我本机得到的结果：
C:\Java\jdk1.5.0_04\bin; .;C:\WINDOWS\system32;C:\WINDOWS;C:\Java\jdk1.5.0_04\bin;D:\oracle\ora92\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\Program Files\Oracle\jre\1.1.8\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;E:\apache-ant-1.6.3\bin;E:\maven-1.0.2\bin;D:\mysql-5.0.45-win32\bin;C:\Program Files\OpenSSH\bin;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\Subversion\bin
 
观察上面的java.library.path的值，可以看到它大概包括了三部分，即windows系统环境变量中PATH + JAVA_HOME/bin + 系统路径（.;C:\WINDOWS\system32;C:\WINDOWS;）
 
注2： 为了不依赖于alfresco/bin/Win32NetBIOS.dll这个路径（如果你下载不是 alfresco-community-tomcat-2.1.0.zip 这种内嵌tomcat的版本，而是一个单独的 alfresco-community-war-2.1.0.zip ，这点会非常有用），你可以把Win32NetBIOS.dll拷贝到C:\Java\jdk1.5.0_04\bin或C:\WINDOWS\system32路径中，删除alfresco/bin/Win32NetBIOS.dll依然可以使用alfresco/alf_start.bat正常启动alfresco。
 
⑺ 下面出错信息：
org.alfresco.error.AlfrescoRuntimeException: Ensure that the 'dir.root' property
 is pointing to the correct data location.
 
alfresco\tomcat\webapps\alfresco\WEB-INF\classes\alfresco 下的repository.properties文件中：
# Change the failure behaviour of the configuration checker
system.bootstrap.config_check.strict=true
改为：
# Change the failure behaviour of the configuration checker
system.bootstrap.config_check.strict=false
 
16:30:32,546 ERROR  CONTENT INTEGRITY ERROR: Indexes not found for 5 stores.
alfresco\tomcat\webapps\alfresco\WEB-INF\classes\alfresco 下的repository.properties文件中：
# The index recovery mode (NONE, VALIDATE, AUTO, FULL)
index.recovery.mode=VALIDATE
 
改为：
# The index recovery mode (NONE, VALIDATE, AUTO, FULL)
index.recovery.mode=FULL
可以重新创建索引。
 
 
2 ． alfresco 默认数据库HSQL database
① alfresco默认使用的数据库为HSQL database，可在alfresco\tomcat\shared\classes\alfresco\extension中找到两个与数据库定义相关的文件custom-hibernate-dialect.properties和custom-repository.properties（还可以定义一些其它系统配置），其中
custom-hibernate-dialect.properties ：
hibernate.dialect=org.hibernate.dialect.HSQLDialect
 
custom-repository.properties ：
db.driver=org.hsqldb.jdbcDriver
db.url=jdbc:hsqldb:file:alf_data/hsql_data/alfresco;ifexists=true;shutdown=true;
 
这两个文件是在alfresco\tomcat\shared\classes\alfresco\extension\custom-repository-context.xml中加载的。
 
② 在alfresco\tomcat\webapps\alfresco\WEB-INF\classes\alfresco下有另外的一个文件repository.properties，这个文件与上面的custom-repository.properties相对应，如果在两个properties文件中定义了相同的key/value资源，在加载文件中的资源时，custom-repository.properties会覆盖repository.properties中的（实际上是map中value被覆盖），这与两者的加载顺序有关：
alfresco\tomcat\webapps\alfresco\WEB-INF\classes\alfresco\application-context.xml 中先后加载（见下）。
<import resource="classpath:alfresco/core-services-context.xml" />
<import resource="classpath*:alfresco/extension/*-context.xml"/>
 
repository.properties 与custom-repository.properties分别在core-services-context.xml与custom-repository-context.xml中指定
 
注 ： 查看repository.properties文件，可以看到
db.username=alfresco
db.password=alfresco
这与上面1．- ② - ⑶ 中使用alfresco.script创建HSQL数据库用户的sql语句是对应的。
 
 
3 ． 把hsql转为mysql（使用帮助也可参考alfresco/ README_mysql.txt ）
① alfresco 使用mysql数据库
⑴ 实际发布的时候一般不建议使用HSQL database这种文件型数据库。
启动alf_start.bat可以看到控制台有一行提示：
11:10:57,062 INFO   Alfresco is using the HSQL de
fault database. Please only use this while evaluating Alfresco, it is NOT recomm
ended for production or deployment!
 
使用mysql数据库前清空文件夹：alfresco/alf_data（其中alfresco/alf_data/hsql_data文件夹可以删除，因为这时已经用不到HSQL数据库了），alfresco/tomcat/temp, alfresco/tomcat/work。
 
⑵ 打开alfresco/extras/databases/mysql下的db_setup.sql，可以看到：
create database alfresco;
grant all on alfresco.* to 'alfresco'@'localhost' identified by 'alfresco' with grant option;
grant all on alfresco.* to 'alfresco'@'localhost.localdomain' identified by 'alfresco' with grant option;
上面创建了alfresco数据库，并创建用户名alfresco密码alfresco，分配管理权限。
 
为确保国际化，统一使用UTF8编码（alfresco/ README_mysql.txt 中也有提到），db_setup.sql修改为：
create database alfresco DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
grant all on alfresco.* to 'alfresco'@'localhost' identified by 'alfresco' with grant option;
grant all on alfresco.* to 'alfresco'@'localhost.localdomain' identified by 'alfresco' with grant option;
 
运行alfresco/extras/databases/mysql/db_setup.bat，即可创建mysql数据库。
 
② alfresco\tomcat\shared\classes\alfresco\extension 中找到两个与数据库定义相关的文件custom-hibernate-dialect.properties和custom-repository.properties（还可以定义一些其它系统配置），其中
custom-hibernate-dialect.properties ：
hibernate.dialect=org.hibernate.dialect.HSQLDialect
 
custom-repository.properties ：
db.driver=org.hsqldb.jdbcDriver
db.url=jdbc:hsqldb:file:alf_data/hsql_data/alfresco;ifexists=true;shutdown=true;
修改为
custom-hibernate-dialect.properties ：
#hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
 
custom-repository.properties ：
#db.driver=org.hsqldb.jdbcDriver
#db.url=jdbc:hsqldb:file:alf_data/hsql_data/alfresco;ifexists=true;shutdown=true;
db.driver=org.gjt.mm.mysql.Driver
db.url=jdbc:mysql://localhost/alfresco
 
默认的alfresco数据库用户名和密码位于alfresco\tomcat\webapps\alfresco\WEB-INF\classes\alfresco下的repository.properties文件中（可参考2．- ② -注）。
 
 
③ 启动alfresco/alf_start.bat，可以看到在alfresco/alf_data下生成4个文件夹：lucene-indexes/contentstore.deleted/contentstore/audit.contentstore。
 
alfresco\tomcat\webapps\alfresco\WEB-INF\classes\alfresco 下的repository.properties文件中定义了这些初始化参数：
# Directory configuration
dir.root=./alf_data
dir.contentstore=${dir.root}/contentstore
dir.contentstore.deleted=${dir.root}/contentstore.deleted
dir.auditcontentstore=${dir.root}/audit.contentstore
 
# The location for lucene index files
dir.indexes=${dir.root}/lucene-indexes
# The location for lucene index locks
dir.indexes.lock=${dir.indexes}/locks
 
注： alfresco 数据库中保存的是一些数据库关系（以及JBPM的一些表），比如预定义的permission/node/access_control等，而数据(data)和内容(content)保存在alfresco/alf_data文件夹下。
 
 
4 ． 使用mysql数据库乱码问题
① 如上3．转换为mysql数据库后，访问http://localhost:8080/alfresco/如果语言选择中文，进入系统后一些地方会出现中文乱码。
我使用的是mysql-5.0.45-win32解压版数据库，如果出现乱码，首先确保你数据库编码设置正确，使用show variables like 'chara%';查看你数据库编码，比较重要的有四个编码：
character_set_client : 客户端字符集(应用程序客户端使用的字符集)。
character_set_connection : 连接字符集。
character_set_results : 指的是使用sql查询处理以后返回结果使用的字符集。
character_set_database : 指的数据库表中物理存储使用的字符集。
 
因为alfresco代码使用的是utf8格式，所以在使用
create database alfresco DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
创建数据库之前，首先设置mysql数据库编码，这样在启动alfresco/alf_start.bat初始化mysql数据库时（创建alfresco表和数据）时，才能保证表和数据格式的正确。
set character_set_database='gbk';  （设置为gbk可以在查看表数据时显示中文数据）
set names 'utf8'; （设置character_set_client/ character_set_connection/ character_set_results字符集）
 
alfresco\tomcat\shared\classes\alfresco\extension 中
custom-repository.properties ：
db.url=jdbc:mysql://localhost/alfresco
修改为
custom-repository.properties ：
db.url=jdbc:mysql://localhost/alfresco?characterEncoding=gbk&useUnicode=true