mybatis的配置
SqlSessionFactory的构造
package MS.mybatis;
import java.io.IOException;
import java.io.Reader;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
public abstract class MybatisUtil {
private static SqlSessionFactory sqlSessionFactory=null;
static
{
try {
String resource = "mybatis-config.xml";
Reader reader = Resources.getResourceAsReader(resource);
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static SqlSessionFactory getSqlSessionFactory()
{
return sqlSessionFactory;
}
public static SqlSession getSqlSession()
{
return sqlSessionFactory.openSession();
}
}
报错信息如下:
20:53:05,537 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC0000
01: Failed to start service jboss.deployment.unit."MessageSystem.jar".POST_MODUL
E: org.jboss.msc.service.StartException in service jboss.deployment.unit."Messag
eSystem.jar".POST_MODULE: JBAS018733: 处理 POST_MODULE 的 deployment "MessageSys
tem.jar" 阶段失败
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(Deplo
ymentUnitPhaseService.java:127) [jboss-as-server-7.3.0.Final-redhat-14.jar:7.3.0
.Final-redhat-14]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(Se
rviceControllerImpl.java:1811) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-redhat-
1]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceCont
rollerImpl.java:1746) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-redhat-1]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
utor.java:886) [rt.jar:1.6.0_26]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:908) [rt.jar:1.6.0_26]
at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_26]
Caused by: java.lang.RuntimeException: JBAS018757: 获得带有类加载器 class MS.myb
atis.MybatisUtil 的 ModuleClassLoader for Module "deployment.MessageSystem.jar:m
ain" from Service Module Loader 的反射信息出错
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getC
lassIndex(DeploymentReflectionIndex.java:72) [jboss-as-server-7.3.0.Final-redhat
-14.jar:7.3.0.Final-redhat-14]
at org.jboss.as.ee.metadata.MethodAnnotationAggregator.runtimeAnnotation
Information(MethodAnnotationAggregator.java:58)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.ha
ndleAnnotations(InterceptorAnnotationProcessor.java:107)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.pr
ocessComponentConfig(InterceptorAnnotationProcessor.java:92)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.de
ploy(InterceptorAnnotationProcessor.java:77)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(Deplo
ymentUnitPhaseService.java:120) [jboss-as-server-7.3.0.Final-redhat-14.jar:7.3.0
.Final-redhat-14]
... 5 more
Caused by: java.lang.NoClassDefFoundError: Lorg/apache/ibatis/session/SqlSession
Factory;
at java.lang.Class.getDeclaredFields0(Native Method) [rt.jar:1.6.0_26]
at java.lang.Class.privateGetDeclaredFields(Class.java:2291) [rt.jar:1.6
.0_26]
at java.lang.Class.getDeclaredFields(Class.java:1743) [rt.jar:1.6.0_26]
at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.(Cl
assReflectionIndex.java:57) [jboss-as-server-7.3.0.Final-redhat-14.jar:7.3.0.Fin
al-redhat-14]
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getC
lassIndex(DeploymentReflectionIndex.java:68) [jboss-as-server-7.3.0.Final-redhat
-14.jar:7.3.0.Final-redhat-14]
... 10 more
Caused by: java.lang.ClassNotFoundException: org.apache.ibatis.session.SqlSessio
nFactory from [Module "deployment.MessageSystem.jar:main" from Service Module Lo
ader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:
197) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(Con
currentClassLoader.java:443) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(Concu
rrentClassLoader.java:431) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(Concu
rrentClassLoader.java:398) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentCl
assLoader.java:373) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoad
er.java:118) [jboss-modules.jar:1.3.0.Final-redhat-2]
... 15 more