多数据源spring 报java.lang.NullPointerException

在调用test.java的时候就会报

Exception in thread "main" java.lang.NullPointerException
at cn.m_solution.mds.mds40.service.MDS40T01Service.getStudent(MDS40T01Service.java:23)
at cn.m_solution.mds.mds40.service.test.main(test.java:13)

请大家一定帮忙,已经弄了两天了

[color=red]moduleContext-sys.xml:[/color]

<?xml version="1.0" encoding="UTF-8" ?>

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<!-- +++++++++++++++++++++++++++++++++++++++++ -->
<!-- 系统关联设定(必须)                        -->
<!-- +++++++++++++++++++++++++++++++++++++++++ -->
<bean id="ApplicationInfo"
    class="net.uniuvo.webridger.beans.ApplicationInfo">

    <!-- 应用系统名称  -->
    <property name="applicationName" value="mds" />

    <!-- 允许直接访问的Action列表  -->
    <property name="directAccessActions">
        <list>
            <value>mds00.do</value>
            <value>/mds13.do</value>
            <value>/mds40.do</value>
        </list>
    </property>

    <!-- 禁止访问的扩展名列表  -->
    <property name="prohibitedExtensions">
        <list>
            <value>js</value>
            <value>css</value>
            <value>jsp</value>
            <value>html</value>
        </list>
    </property>

    <!-- 禁止访问的扩展名中例外的文件列表  -->
    <property name="restrictionEscapeFiles">
        <list>
            <value>/pages/index.html</value>
            <value>/pages/mds40/mds40s00.jsp</value>
        </list>
    </property>

</bean>

<!-- +++++++++++++++++++++++++++++++++++++++++ -->
<!-- 数据库关联设定(必须)                      -->
<!--此bean告诉Spring去哪找数据库的配置信息,因为有此Bean才出现下面用${}标记来取变量的语句-->   
<!-- +++++++++++++++++++++++++++++++++++++++++ -->
<!-- 这里定义了ibatis的配置文件所在的位置 -->
<bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
        <value>/WEB-INF/config/jdbc/jdbc.properties</value>
    </property>
</bean>

<!-- destroy-method="close">-->
destroy-method="close">




<bean id="ds1" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="${jdbc.driverClassName1}" />
    <property name="url" value="${jdbc.url1}" />
    <property name="username" value="${jdbc.username1}" />
    <property name="password" value="${jdbc.password1}" />
</bean>









<!--这里就声明了具体的事务 -->
<bean id="attrSource"
    class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
    <property name="properties">
        <props>
            <prop key="execute*">PROPAGATION_REQUIRED</prop>
            <prop key="update*">PROPAGATION_REQUIRED</prop>
            <prop key="insert*">PROPAGATION_REQUIRED</prop>
            <prop key="delete*">PROPAGATION_REQUIRED</prop>
            <prop key="select*">PROPAGATION_REQUIRED</prop>
        </props>
    </property>
</bean>

<!-- 定义事务处理拦截器 -->
<bean id="transactionInterceptor"
    class="org.springframework.transaction.interceptor.TransactionInterceptor">
    <property name="transactionManager">
        <ref local="transactionManager" />
    </property>
    <property name="transactionAttributeSource">
        <ref local="attrSource" />
    </property>
</bean>

<!-- 定义事务经理 -->
<bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource">
        <ref local="DataSource" />
    </property>
</bean>

<!-- 自动代理 (业务处理Bean的Id) -->
<bean id="autoProxy"
    class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
    <property name="interceptorNames">
        <list>
            <idref bean="transactionInterceptor" />
        </list>
    </property>
    <property name="beanNames">
        <list>
            <value>*Service</value>
        </list>
    </property>
</bean>

<!-- iBATIS相关设定 -->
<bean id="sqlMapClient"
    class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
    <property name="configLocation" value="/WEB-INF/sqlMapConfig.xml" />
    <property name="dataSource">
        <ref bean="DataSource" />
    </property>

    <property name="lobHandler">
        <ref local="oracleLobHandler" />
    </property>
</bean>

<!-- 定义DAO -->
<!-- 检索用DAO -->
<bean id="queryDAO" 
    class="net.uniuvo.webridger.dao.QueryDAOiBatisImpl">
    <property name="sqlMapClient">
        <ref local="sqlMapClient" />
    </property>
</bean>

<!-- 追加 更新 删除用DAO -->
<bean id="updateDAO"
    class="net.uniuvo.webridger.dao.UpdateDAOiBatisImpl">
    <property name="sqlMapClient">
        <ref local="sqlMapClient" />
    </property>
</bean>

<!--根据sqlMapClien创建一个SqlMapClient模版类-->
<bean id="SqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
    <property name="sqlMapClient">
        <ref bean="sqlMapClient" />
    </property>
</bean>

<bean id="nativeJdbcExtractor" lazy-init="true"
    class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor" />

<bean id="oracleLobHandler" lazy-init="true"
    class="org.springframework.jdbc.support.lob.OracleLobHandler" >
    <property name="nativeJdbcExtractor"><ref local="nativeJdbcExtractor"/></property>
</bean>

<!-- 这里就是Facade了,注意,它有个parent属性,就是这个属性,使它的操作受到了事物管理的限制
<bean id="baseFacade" parent="baseTransactionProxy">
    <property name="target">
        <bean class="facade.BaseFacadeImpl"> 把DAO做为属性注入到Facade中去
            <property name="proDao" ref="proDao" />
            <property name="errDao" ref="errDao" />
            <property name="userDao" ref="userDao" />
            <property name="orderDao" ref="orderDao" />
        </bean>
    </property>
</bean>
 -->

[color=red]sqlmapconfig.xml[/color]

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">


<sqlMap resource="../config/sql/sqlMap-mds.xml" />
<sqlMap resource="../config/sql/sqlMap-mds00.xml" />
<sqlMap resource="../config/sql/sqlMap-mds01.xml" />
<sqlMap resource="../config/sql/sqlMap-mds02.xml" />
<sqlMap resource="../config/sql/sqlMap-mds03.xml" />
<sqlMap resource="../config/sql/sqlMap-mds04.xml" />
<sqlMap resource="../config/sql/sqlMap-mds10.xml" />
<sqlMap resource="../config/sql/sqlMap-mds11.xml" />
<sqlMap resource="../config/sql/sqlMap-mds12.xml" />
<sqlMap resource="../config/sql/sqlMap-mds13.xml" />
<sqlMap resource="../config/sql/sqlMap-mds20.xml" />
<sqlMap resource="../config/sql/sqlMap-mds21.xml" />
<sqlMap resource="../config/sql/sqlMap-mds22.xml" />
<sqlMap resource="../config/sql/sqlMap-mds23.xml" /> 
<sqlMap resource="../config/sql/sqlMap-mds30.xml" /> 
<sqlMap resource="../config/sql/sqlMap-mds31.xml" />
<sqlMap resource="../config/sql/sqlMap-mds32.xml" />
<sqlMap resource="../config/sql/sqlMap-mds33.xml" />
<sqlMap resource="../config/sql/sqlMap-mds40.xml" />

sqlMap-mds40.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-2.dtd">

<select id="sql.mds40.001" 
    parameterClass="cn.m_solution.mds.mds40.form.MDS40Form" 
    resultClass="cn.m_solution.mds.mds40.form.MDS40Form">
     select 
        syr
    from 
        vehicle
    where 
        hpzl = #hpzl#
        and hphm = #hphm#
</select>

MDS40T01Service

package cn.m_solution.mds.mds40.service;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

import cn.m_solution.mds.mds40.form.MDS40Form;

public class MDS40T01Service {
SqlMapClientTemplate sqlMapClientTemplate;

public MDS40Form getStudent(){

    MDS40Form form40 = new MDS40Form();
    sqlMapClientTemplate.queryForObject("sql.mds40.001",form40);
    return form40;
}
/**
 * @return the sqlMapClientTemplate
 */
public SqlMapClientTemplate getSqlMapClientTemplate() {
    return sqlMapClientTemplate;
}

/**
 * @param sqlMapClientTemplate the sqlMapClientTemplate to set
 */
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) {
    this.sqlMapClientTemplate = sqlMapClientTemplate;
}

}

test.java

package cn.m_solution.mds.mds40.service;

import org.springframework.jdbc.core.support.JdbcDaoSupport;

public class test extends JdbcDaoSupport{

/**
 * @param args
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub
    MDS40T01Service s = new MDS40T01Service();
    s.getStudent();
}

}

4个回答

[quote]public MDS40Form getStudent(){

MDS40Form form40 = new MDS40Form();
sqlMapClientTemplate.queryForObject("sql.mds40.001",form40);
return form40;
} [/quote]
这个方法是用来调用数据的对吧?你在这new了一个对象,那么对象是什么?空的对象。
在看这,
[quote] parameterClass="cn.m_solution.mds.mds40.form.MDS40Form"
resultClass="cn.m_solution.mds.mds40.form.MDS40Form">
select
syr
from
vehicle
where
hpzl = #hpzl#
and hphm = #hphm#
[/quote]
这里的parameterClass是要对象参数的。在sql语句中有用到吧。可是你现在在类中给的是空的字符串,你说能查出东西吗?既然没东西返回一定是空值。报空指针异常。

MDS40T01Service 怎么是new出来的,不是loadbean load出来的?

[quote]我就是想通过一个main方法直接调用service来进行查询!
[/quote]
Servie要load出来,不能new出来,不然spring怎么把temple inject进去?

sqlMapClientTemplate 没有注入~ 所以是空的,
如果你非得这么测试的话,先
[code="java"]
ApplicationContext context = new FileSystemXmlApplicationContext("application.xml");

[/code]然后获得Bean中的
SqlMapClientTemplate
[code="java"]
SqlMapClientTemplate sqlMap = (SqlMapClientTemplate )context.getBean("SqlMapClientTemplate");
[/code]
然后
[code="java"]
MDS40T01Service s = new MDS40T01Service();
s.setSqlMapClientTemplate(sqlMap);
s.getStudent();
[/code]
这样应该就不会报空了~ 试试

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
JDBC-ODBC桥连接时出现空指针异常

我在用 jdbc-odbc 桥连方式操作 sql server 数据库时出现空指针异常 Connection ct = null; Statement sm = null; try { //(1)加载驱动(作用是把需要的驱动程序加入内存) Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //(2)得到连接(指定连接到哪个数据库) ct = DriverManager.getConnection("jdbc:odbc:mytest"); System.out.println("数据库成功连接"); //(3)创建Statement或者preparedStatement sm = ct.createStatement(); //(4)执行CRUD //添加一条数据到dept表 int i = sm.executeUpdate("insert into dept values('50','security','beijing')"); if(i==1){ System.out.println("添加成功"); }else{ System.out.println("添加失败"); } } catch (Exception e) { e.printStackTrace(); }finally{ //以上的语句执行完成之后需要关闭数据源 //关闭的顺序:谁先创建谁后关闭 try{ if(sm != null){ sm.close(); } if(ct != null){ ct.close(); } }catch (SQLException e){ e.printStackTrace(); } } 出现异常描述如下: java.lang.NullPointerException at sun.jdbc.odbc.JdbcOdbcDriver.initialize(JdbcOdbcDriver.java:436) at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:153) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:270) at JDBC_ODBC.main(JDBC_ODBC.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

weblogic部署时报错竟然有这样特殊的空指针异常,

<2015-5-12 上午01时15分18秒 GMT> <Error> <HTTP> <BEA-101165> <Could not load user defined filter in web.xml: org.acegisecurity.util.FilterToBeanProxy. org.springframework.beans.factory.BeanDefinitionStoreException: Error registering bean with name 'xfire.typeMappingRegistry' defined in class path resource [org/codehaus/xfire/spring/xfire.xml]: Unexpected failure during bean definition parsing; nested exception is java.lang.NoSuchMethodError: javax.xml.namespace.QName.<init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V java.lang.NoSuchMethodError: javax.xml.namespace.QName.<init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V at org.codehaus.xfire.aegis.type.DefaultTypeMappingRegistry.<clinit>(DefaultTypeMappingRegistry.java:66) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:219) at org.springframework.util.ClassUtils.forName(ClassUtils.java:109) at org.springframework.beans.factory.support.BeanDefinitionReaderUtils.createBeanDefinition(BeanDefinitionReaderUtils.java:65) at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitionElement(DefaultXmlBeanDefinitionParser.java:496) at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitionElement(DefaultXmlBeanDefinitionParser.java:462) at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitions(DefaultXmlBeanDefinitionParser.java:374) at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.registerBeanDefinitions(DefaultXmlBeanDefinitionParser.java:182) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:295) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:223) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:173) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:223) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:173) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:148) at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.registerBeanDefinitions(DefaultXmlBeanDefinitionParser.java:182) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:295) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:223) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:173) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:148) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:129) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:145) at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.importBeanDefinitionResource(DefaultXmlBeanDefinitionParser.java:395) at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitions(DefaultXmlBeanDefinitionParser.java:365) at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.registerBeanDefinitions(DefaultXmlBeanDefinitionParser.java:182) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:295) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:223) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:173) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:148) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:129) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:145) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:132) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:100) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:89) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:262) at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:139) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:252) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:190) at gov.mof.framework.bpo.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:48) at weblogic.servlet.internal.WebAppServletContext$FireContextListenerAction.run(WebAppServletContext.java:7110) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121) at weblogic.servlet.internal.WebAppServletContext.notifyCreated(WebAppServletContext.java:1757) at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:3378) at weblogic.servlet.internal.WebAppServletContext.setStarted(WebAppServletContext.java:6262) at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:892) at weblogic.j2ee.J2EEApplicationContainer.start(J2EEApplicationContainer.java:2181) at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:2222) at weblogic.management.deploy.slave.SlaveDeployer$ComponentActivateTask.activateContainer(SlaveDeployer.java:2521) at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.doCommit(SlaveDeployer.java:2439) at weblogic.management.deploy.slave.SlaveDeployer$Task.commit(SlaveDeployer.java:2156) at weblogic.management.deploy.slave.SlaveDeployer$Task.checkAutoCommit(SlaveDeployer.java:2255) at weblogic.management.deploy.slave.SlaveDeployer$Task.prepare(SlaveDeployer.java:2150) at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.prepare(SlaveDeployer.java:2402) at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer.java:884) at weblogic.management.deploy.slave.SlaveDeployer.prepareDelta(SlaveDeployer.java:592) at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java:501) at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:25) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183) > <2015-5-12 上午01时15分18秒 GMT> <Warning> <Deployer> <BEA-149004> <Failures were detected while initiating Deploy task for application WebRoot.> <2015-5-12 上午01时15分18秒 GMT> <Error> <Deployer> <BEA-149201> <Failed to complete the deployment task with ID 0 for the application WebRoot. weblogic.management.DeploymentException: Exception:weblogic.management.ApplicationException: start() failed. Module: WebRoot Error: java.lang.NullPointerException at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.doCommit(SlaveDeployer.java:2441) at weblogic.management.deploy.slave.SlaveDeployer$Task.commit(SlaveDeployer.java:2156) at weblogic.management.deploy.slave.SlaveDeployer$Task.checkAutoCommit(SlaveDeployer.java:2255) at weblogic.management.deploy.slave.SlaveDeployer$Task.prepare(SlaveDeployer.java:2150) at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.prepare(SlaveDeployer.java:2402) at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer.java:884) at weblogic.management.deploy.slave.SlaveDeployer.prepareDelta(SlaveDeployer.java:592) at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java:501) at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:25) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183) --------------- nested within: ------------------ weblogic.management.ManagementException: - with nested exception: [weblogic.management.DeploymentException: Exception:weblogic.management.ApplicationException: start() failed. Module: WebRoot Error: java.lang.NullPointerException ] at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.prepare(SlaveDeployer.java:2414) at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer.java:884) at weblogic.management.deploy.slave.SlaveDeployer.prepareDelta(SlaveDeployer.java:592) at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java:501) at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:25) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183) >

菜鸟:高手帮看一下什么 原因?用代理方式时jdbcTemplate为NULL

<p>用代理方式执行时jdbcTemplate为NULL,高手帮看一下怎么回事呀????</p> <p> </p> <p>Exception in thread "main" java.lang.reflect.InvocationTargetException<br> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br> at java.lang.reflect.Method.invoke(Method.java:597)<br> at com.okgj.core.MessageExecutor.invoke(MessageExecutor.java:46)<br> at com.okgj.core.MessageExecutor.main(MessageExecutor.java:64)<br>Caused by: java.lang.NullPointerException<br> at com.okgj.service.dao.impl.UserDaoImpl.getUserInfo(UserDaoImpl.java:42)<br> at com.okgj.service.impl.UserServiceImpl.getUserInfo(UserServiceImpl.java:43)<br> at com.okgj.service.impl.UserServiceImpl$$EnhancerByCGLIB$$398c34af.getUserInfo(&lt;generated&gt;)<br> ... 6 more</p> <p> </p> <p>package com.okgj.service.dao.impl;<br><br>import java.util.ArrayList;<br>import java.util.List;<br><br>import javax.annotation.Resource;<br><br>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.jdbc.core.JdbcTemplate;<br>import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;<br>import org.springframework.jdbc.core.support.JdbcDaoSupport;<br>import org.springframework.orm.hibernate3.HibernateTemplate;<br>import org.springframework.stereotype.Repository;<br><br>import com.okgj.service.dao.UserDao;<br>import com.okgj.service.entity.userInfo;<br><br>@Repository<br>public class UserDaoImpl implements UserDao {<br><br>    private JdbcTemplate jdbcTemplate;<br><br>    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {<br>        this.jdbcTemplate = jdbcTemplate;<br>    }<br><br>    public JdbcTemplate getJdbcTemplate() {<br>        return jdbcTemplate;<br>    }<br><br>    @Override<br>    public List getUserInfo(String condition) {<br>        String sql = "select username,userpwd from tb_user";<br>        List userList = jdbcTemplate.queryForList(sql);<br>        return userList;<br>    }<br>}</p> <p> </p> <p>debug下面类时不会出错,</p> <p> </p> <p>package com.okgj.service.impl;<br><br>import java.lang.reflect.Method;<br>import java.util.List;<br><br>import javax.annotation.Resource;<br><br>import org.springframework.context.ApplicationContext;<br>import org.springframework.context.support.FileSystemXmlApplicationContext;<br>import org.springframework.stereotype.Service;<br>import org.springframework.transaction.annotation.Transactional;<br><br>import com.okgj.service.UserService;<br>import com.okgj.service.dao.UserDao;<br>import com.okgj.service.dao.impl.UserDaoImpl;<br><br>import org.springframework.transaction.annotation.Propagation;<br><br>@Service<br>@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)<br>public class UserServiceImpl implements UserService {<br>    @Resource<br>    private UserDao userDao = new UserDaoImpl();<br><br>    public UserDao getUserDao() {<br>        return userDao;<br>    }<br><br>    public void setUserDao(UserDao userDao) {<br>        this.userDao = userDao;<br>    }<br><br>    public List getUserInfo(String condition) {<br>        return userDao.getUserInfo(condition);<br>    }<br><br>    public static void main(String[] args) throws Throwable {<br>        ApplicationContext context = new FileSystemXmlApplicationContext(<br>                "classpath:spring-service.xml");<br>         UserService userService = (UserService)<br>         context.getBean("userService");<br>        <br>         List list = userService.getUserInfo("");<br>         System.out.println(list.toString());<br><br>    }<br><br>}</p> <p> </p> <p>而通过代理的方式执行却报上面的错,为什么 呀?急呀!!!!!!</p> <p> </p> <p>package com.okgj.service.impl;<br><br>import java.lang.reflect.Method;<br>import java.util.List;<br><br>import javax.annotation.Resource;<br><br>import org.springframework.context.ApplicationContext;<br>import org.springframework.context.support.FileSystemXmlApplicationContext;<br>import org.springframework.stereotype.Service;<br>import org.springframework.transaction.annotation.Transactional;<br><br>import com.okgj.service.UserService;<br>import com.okgj.service.dao.UserDao;<br>import com.okgj.service.dao.impl.UserDaoImpl;<br><br>import org.springframework.transaction.annotation.Propagation;<br><br>@Service<br>@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)<br>public class UserServiceImpl implements UserService {<br>    @Resource<br>    private UserDao userDao = new UserDaoImpl();<br><br>    public UserDao getUserDao() {<br>        return userDao;<br>    }<br><br>    public void setUserDao(UserDao userDao) {<br>        this.userDao = userDao;<br>    }<br><br>    public List getUserInfo(String condition) {<br>        return userDao.getUserInfo(condition);<br>    }<br><br>    public static void main(String[] args) throws Throwable {<br>        ApplicationContext context = new FileSystemXmlApplicationContext(<br>                "classpath:spring-service.xml");<br>        <br><br>        Class&lt;?&gt; c = (Class&lt;?&gt;) context.getBean("userService").getClass();<br>        Object obj = c.newInstance();<br><br>        Method m = c.getMethod("getUserInfo",<br>                new Class[] { java.lang.String.class });<br>        Object result = m.invoke(obj, new Object[] { "" });<br>    }<br><br>}</p> <p> </p> <p>spring的配置文件如下:</p> <p>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br><br>&lt;beans xmlns="http://www.springframework.org/schema/beans"<br>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"<br>    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"<br>    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd<br>                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd<br>                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd<br>                http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"&gt;<br><br>    &lt;import resource="spring-db-connectionpool.xml" /&gt;<br><br>    &lt;bean id="userService" class="com.okgj.service.impl.UserServiceImpl"&gt;<br>        &lt;property name="userDao" ref="userDao" /&gt;<br>    &lt;/bean&gt;<br>    &lt;bean id="orderService" class="com.okgj.service.impl.OrderServiceImpl"&gt;<br>        &lt;property name="userDao" ref="userDao" /&gt;<br>    &lt;/bean&gt;<br>    &lt;bean id="userDao" class="com.okgj.service.dao.impl.UserDaoImpl"&gt;<br>        &lt;property name="jdbcTemplate" ref="jdbcTemplate" /&gt;<br>    &lt;/bean&gt;<br><br>&lt;/beans&gt;</p> <p> </p> <p>&lt;!--数据源配置,使用应用内的C3P0数据库连接池  --&gt;<br>    &lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"<br>        destroy-method="close"&gt;<br>        &lt;property name="driverClass" value="com.mysql.jdbc.Driver" /&gt;<br>        &lt;property name="jdbcUrl" value="jdbc:mysql://localhost/projectmanagesystem" /&gt;<br>        &lt;property name="user" value="root" /&gt;<br>        &lt;property name="password" value="" /&gt;<br>        &lt;property name="numHelperThreads" value="5" /&gt;<br>        &lt;property name="maxPoolSize" value="20" /&gt;<br>        &lt;property name="minPoolSize" value="5" /&gt;<br>        &lt;property name="initialPoolSize" value="5" /&gt;<br>    &lt;/bean&gt;</p> <p> </p> <p>&lt;!-- 添加AnnotationSessionFactoryBean,提供注解注入支持 --&gt;<br>    &lt;bean id="sessionFactory"<br>        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;<br>        &lt;property name="dataSource" ref="dataSource" /&gt;<br>        &lt;property name="packagesToScan"&gt;<br>            &lt;list&gt;<br>                &lt;value&gt;com.okgj.service.*&lt;/value&gt;<br>            &lt;/list&gt;<br>        &lt;/property&gt;<br>        &lt;property name="hibernateProperties"&gt;<br>            &lt;props&gt;<br>                &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;<br>                &lt;prop key="hibernate.show_sql"&gt;false&lt;/prop&gt;<br>                &lt;prop key="hibernate.hbm2ddl.auto"&gt;create&lt;/prop&gt;<br>                &lt;prop key="hibernate.format_sql"&gt;false&lt;/prop&gt;<br>                &lt;!-- &lt;prop key="hibernate.connection.autocommit"&gt;true &lt;/prop&gt;--&gt;<br>                &lt;prop key="hibernate.cache.provider_class"&gt;<br>                    net.sf.ehcache.hibernate.EhCacheProvider<br>                &lt;/prop&gt;<br>                &lt;prop key="hibernate.cache.use_query_cache"&gt;true&lt;/prop&gt;<br>            &lt;/props&gt;<br>        &lt;/property&gt;<br>    &lt;/bean&gt;<br><br>    &lt;bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"&gt;<br>        &lt;property name="sessionFactory" ref="sessionFactory" /&gt;<br>    &lt;/bean&gt;<br><br>    &lt;!--   JdbcTemplate   --&gt;<br>    &lt;bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"&gt;<br>        &lt;property name="dataSource" ref="dataSource" /&gt;<br>    &lt;/bean&gt;</p> <p> </p>

仅仅只用mybatis框架操作数据库 设置懒加载后报错:创建延时代理出错,空指针异常

如果不设置懒加载,数据能读出来, 设置懒加载后,报错 Cause: org.apache.ibatis.executor.ExecutorException: Error creating lazy proxy. Cause: java.lang.NullPointerException mybatis版本3.46 配置文件 Order <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.gyf.mapper.OrderMapper"> <!-- ============= 懒加载 ==================--> <resultMap id="orderLazyloadingRslMap" type="orders"> <id column="id" property="id"/> <id column="user_id" property="user_id"></id> <result column="note" property="note"/> <result column="number" property="number"/> <result column="createtime" property="createtime"/> <!--配置查询--> <association property="user" javaType="com.gyf.model.User" select="com.gyf.mapper.UserMapper.findUserById" column="user_id"/> </resultMap> <select id="findOrderAndUserByLazyloading" resultMap="orderLazyloadingRslMap"> SELECT * FROM orders </select> </mapper> 配置文件 User <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.gyf.mapper.UserMapper"> <select id="findUserById" parameterType="int" resultType="user"> SELECT * FROM user WHERE id = #{id} </select> </mapper> sqlMapConfig: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <properties resource="db.properties"/> <!--配置允许懒加载--> <settings> <setting name="lazyLoadingEnabled" value="true"/> </settings> <!--配置别名--> <typeAliases> <!--指定包名,别名就是类名,第一个小写 User 别名就是user--> <package name="com.gyf.model"></package> <package name="com.gyf.vo"></package> </typeAliases> <!-- 配置mybatis的环境信息 --> <environments default="development"> <environment id="development"> <!-- 配置JDBC事务控制,由mybatis进行管理 --> <transactionManager type="JDBC"></transactionManager> <!-- 配置数据源,采用dbcp连接池 --> <dataSource type="POOLED"> <property name="driver" value="${driverClass}"/> <property name="url" value="${url}"/> <property name="username" value="${username}"/> <property name="password" value="${password}"/> </dataSource> </environment> </environments> <!--mybatis加载映射文件--> <mappers> <package name="com.gyf.mapper"></package> </mappers> </configuration> 模型: public class Orders { private Integer id; private Integer user_id; private String note;//备注 private String number; private Date createtime;//写意的创建时间 private User user;//定单所属的用户 public User getUser() { return user; } public void setUser(User user) { this.user = user; } ....get 和 set 方法 } public class User implements Serializable { private int id; private String username;// 用户姓名 private String sex;// 性别 private Date birthday;// 生日 private String address;// 地址 ....get 和 set 方法 } 测试 public class Demo01 { SqlSession session; @Before public void before() throws IOException { System.out.println("before.....获取session"); // a)读取配置文件; InputStream is = Resources.getResourceAsStream("SqlMapConfig.xml"); //b)通过SqlSessionFactoryBuilder创建SqlSessionFactory会话工厂。 SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(is); session = sessionFactory.openSession(); } @After public void after(){ session.close(); } /** * 懒加载 * @throws IOException */ @Test public void test10() throws IOException { OrderMapper mapper = session.getMapper(OrderMapper.class); List<Orders> list = mapper.findOrderAndUserByLazyloading(); for (Orders order : list){ System.out.println("订单信息:"); System.out.println(order); System.out.println("订单所属的客户:"); System.out.println(order.getUser()); } } }

ApplicationContext_common.xml中如何配置oracle数据源?

Spring:applicationcontext_common.xml配置文件: ``` <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd" default-autowire="byName"> <!--注解扫描 --> <context:component-scan base-package="com.liangsw"/> <!-- 配置数据源 --> <!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/userscenter" /> <property name="username" value="root" /> <property name="password" value="root" /> </bean> --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/> <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"/> <property name="username" value="userscenter"/> <property name="password" value="userscenter"/> <!-- 连接池启动时的初始值 --> <property name="initialSize" value="3" /> <!-- 连接池的最大值 --> <property name="maxActive" value="300" /> <property name="maxIdle" value="2" /> <property name="minIdle" value="1" /> </bean> <!-- 配置Mybatis --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 配置Mybatis配置文件 --> <property name="configLocation" value="classpath:mybatis.cfg.xml" /> <!-- 配置映射文件 --> <property name="mapperLocations" value="classpath:config/sqlmapper/*/*Mapper.xml" /> </bean> </beans> ``` POM配置文件添加: ``` <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.1.0</version> </dependency> ``` Junit单元测试类: ``` package com.liangsw.userscenter.common.test; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.liangsw.userscenter.common.utils.ConstatFinalUtil; /** * 测试类的父类 * @author * */ public class BaseTest { protected ApplicationContext ac; /** * 初始化 */ @Before public void init() { ac = new ClassPathXmlApplicationContext("classpath:spring/applicationContext_*.xml"); ConstatFinalUtil.LOGGER.info("----init----ac:{}",ac); } @Test public void test() { ConstatFinalUtil.LOGGER.info("----test-----"); } @After public void close() { ClassPathXmlApplicationContext cpxac = (ClassPathXmlApplicationContext) this.ac; cpxac.close(); ConstatFinalUtil.LOGGER.info("----close-----"); } } ``` Junit控制台报错信息: ``` org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.apache.commons.dbcp.BasicDataSource] for bean with name 'dataSource' defined in file [E:\workspace\eclipse\usersCenter\usersCenter-common\target\classes\spring\applicationContext_common.xml]; nested exception is java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1385) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:641) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:609) at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1484) at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1007) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:741) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) at com.liangsw.userscenter.common.test.BaseTest.init(BaseTest.java:24) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:539) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:207) Caused by: java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at org.springframework.util.ClassUtils.forName(ClassUtils.java:250) at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:401) at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1432) at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1377) ... 34 more java.lang.NullPointerException at com.liangsw.userscenter.common.test.BaseTest.close(BaseTest.java:37) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:539) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:207) ``` 请指导,谢谢!

Spring整合Mybatis时junit控制台报错!

Spring配置文件applicationContext_common.xml: ``` <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd" default-autowire="byName"> <!--注解扫描 --> <context:component-scan base-package="com.liangsw"/> <!-- 配置数据源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/> <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"/> <property name="username" value="userscenter"/> <property name="password" value="userscenter"/> <!-- 连接池启动时的初始值 --> <property name="initialSize" value="3" /> <!-- 连接池的最大值 --> <property name="maxActive" value="300" /> <!-- 最大空闲值. --> <property name="maxIdle" value="2" /> <!-- 最小空闲值. --> <property name="minIdle" value="1" /> </bean> <!--Mybatis配置开始 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!--mybatis配置文件加载 --> <property name="configLocation" value="classpath:mybatis.cfg.xml"/> <!--mybatis映射文件加载 --> <property name="mapperLocations" value="classpath*:config/sqlmapper/*/*Mapper.xml"/> </bean> <!--Mybatis配置结束 --> </beans> ``` Junit控制台报错信息: ``` org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in file [E:\workspace\eclipse\usersCenter\usersCenter-common\target\classes\spring\applicationContext_common.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [mybatis.cfg.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'LOG4J2 '. Cause: java.lang.ClassNotFoundException: Cannot find class: LOG4J2 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:742) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) at com.liangsw.userscenter.common.test.BaseTest.init(BaseTest.java:24) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:539) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:207) Caused by: org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [mybatis.cfg.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'LOG4J2 '. Cause: java.lang.ClassNotFoundException: Cannot find class: LOG4J2 at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:500) at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:380) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ... 36 more Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'LOG4J2 '. Cause: java.lang.ClassNotFoundException: Cannot find class: LOG4J2 at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:121) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:99) at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:494) ... 39 more Caused by: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'LOG4J2 '. Cause: java.lang.ClassNotFoundException: Cannot find class: LOG4J2 at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:118) at org.apache.ibatis.builder.xml.XMLConfigBuilder.settingsElement(XMLConfigBuilder.java:266) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:114) ... 41 more Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias 'LOG4J2 '. Cause: java.lang.ClassNotFoundException: Cannot find class: LOG4J2 at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:120) at org.apache.ibatis.builder.BaseBuilder.resolveAlias(BaseBuilder.java:149) at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:116) ... 43 more Caused by: java.lang.ClassNotFoundException: Cannot find class: LOG4J2 at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:200) at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:89) at org.apache.ibatis.io.Resources.classForName(Resources.java:261) at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:116) ... 45 more java.lang.NullPointerException at com.liangsw.userscenter.common.test.BaseTest.close(BaseTest.java:37) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:539) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:207) ```

spring-boot mybatis 查询mysql报错问题

``` 2018-06-24 17:32:23.171 ERROR 6371 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.lang.NullPointerException ### The error may exist in file [/Users/ww/IdeaProjects/test-Service/test-Search/target/classes/mapping/TestMapper.xml] ### The error may involve com.test.data.mapper.TestMapper.selectByPrimaryKey ### The error occurred while executing a query ### Cause: java.lang.NullPointerException] with root cause java.lang.NullPointerException: null ``` 我的pom.xml ``` <!-- Spring Boot Mybatis--> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.2</version> </dependency> <!-- 数据源 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.0.19</version> </dependency> <!-- MySQL--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.39</version> </dependency> ``` TestMapper.java代码 ``` TestConfig selectByPrimaryKey(Long id); ``` TestMapper.xml ``` <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" > select <include refid="Base_Column_List" /> from test_config where id = #{id,jdbcType=BIGINT} </select> ``` 请各位大神帮忙看一下,几乎所有查询都报这个错误,用了@Param 注释也不行

spring jndi tomcat 配置数据源问题

1 开发环境:eclipse3.6+jdk1.6+mysql5.1+tomcat6.0.18 2 把mysql的驱动包mysql-connector-java-5.0.8-bin.jar放在rist-apache-tomcat-6.0.18\common\lib下面。 3 rist-apache-tomcat-6.0.18\conf\context.xml 在<Context>节点里面添加 <Resource name="jdbc/Rist" auth="Container" type="javax.sql.DataSource" password="admin" username="root" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1:3306/rist" maxActive="100" maxIdle="30" maxWait="5000" /> 4 我项目的web.xml里面添加 <resource-ref> <description>MySQLDBConnection Pool</description> <res-ref-name>jdbc/Rist</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> 5 spring中的配置 <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="java:comp/env/jdbc/Rist"/> </bean> 以上是我所有的配置及环境了但是还是报如下的错误。 [code="java"]Cannot create JDBC driver of class '' for connect URL 'null' java.lang.NullPointerException at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507) at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476) at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307) at java.sql.DriverManager.getDriver(DriverManager.java:253) at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1143) at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880) at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:200) at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:374) at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:263) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:101) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy5.logon(Unknown Source) at com.cmsz.rist.system.action.UsersAction.logon(UsersAction.java:492) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274) at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194) at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58) at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67) at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51) at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191) at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305) at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191) at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.cmsz.rist.common.util.SessionAuthFilter.doFilter(SessionAuthFilter.java:33) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.cmsz.rist.init.SessionAuthFilter.doFilter(SessionAuthFilter.java:45) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:619)[/code] 问题:1 请问是何种原因导致的? 2 我的驱动包放得可对?

weblogic启动报错<log4j:WARN Error during default initialization> ?

最开始weblogic能起成功,我接手的时候weblogic启动失败有报错,然后我重新导入oracle数据库,出现了日志中的错误,排查结果:weblogic单独启动没问题,weblogic部署中数据源测试也是成功的,jar包也一直没动过 最后日志如下 ``` <Sep 11, 2019 10:59:06 AM CST> <Notice> <Stdout> <BEA-000000> <Bundle依赖校验耗时(ms):2> <Sep 11, 2019 10:59:06 AM CST> <Notice> <Stdout> <BEA-000000> <没有不满足的依赖。> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <log4j:WARN Error during default initialization> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <java.lang.NoClassDefFoundError: org/w3c/dom/Node> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at java.lang.Class.getDeclaredConstructors0(Native Method)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at java.lang.Class.privateGetDeclaredConstructors(Class.java:2398)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at java.lang.Class.getConstructor0(Class.java:2708)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at java.lang.Class.newInstance0(Class.java:328)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at java.lang.Class.newInstance(Class.java:310)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.apache.log4j.helpers.OptionConverter.instantiateByClassName(OptionConverter.java:330)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:460)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.apache.log4j.LogManager.<clinit>(LogManager.java:125)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.apache.log4j.Logger.getLogger(Logger.java:105)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:289)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.apache.commons.logging.impl.Log4JLogger.<init>(Log4JLogger.java:109)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at java.lang.reflect.Constructor.newInstance(Constructor.java:513)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.apache.commons.logging.impl.LogFactoryImpl.createLogFromClass(LogFactoryImpl.java:1116)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(LogFactoryImpl.java:914)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:604)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:336)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:310)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at com.ygsoft.ecp.service.osgi.starter.env.SystemConfigurator.<clinit>(SystemConfigurator.java:34)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at com.ygsoft.ecp.service.osgi.starter.Activator.start(Activator.java:51)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:1015)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at java.security.AccessController.doPrivileged(Native Method)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:1009)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:984)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:348)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:357)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1074)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:616)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:508)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:299)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:489)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:211)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:321)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <Caused by: java.lang.ClassNotFoundException: BundleLoader[org.apache.log4j_1.2.15.v201005080500].loadBundleClass(org.w3c.dom.Node)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:407)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:387)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at java.lang.ClassLoader.loadClass(ClassLoader.java:247)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <... 36 more> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <Caused by: java.lang.ClassNotFoundException: org.w3c.dom.Node> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:491)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:404)> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <... 39 more> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <log4j:WARN No appenders could be found for logger (com.ygsoft.ecp.service.osgi.starter.env.SystemConfigurator).> <Sep 11, 2019 10:59:06 AM CST> <Notice> <StdErr> <BEA-000000> <log4j:WARN Please initialize the log4j system properly.> <Sep 11, 2019 10:59:06 AM CST> <Notice> <Log Management> <BEA-170027> <The Server has established connection with the Domain level Diagnostic Service successfully.> <Sep 11, 2019 10:59:06 AM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to ADMIN> <Sep 11, 2019 10:59:06 AM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RESUMING> <Sep 11, 2019 10:59:06 AM CST> <Warning> <Server> <BEA-002611> <Hostname "localhost", maps to multiple IP addresses: 127.0.0.1, 0:0:0:0:0:0:0:1> <Sep 11, 2019 10:59:06 AM CST> <Notice> <Server> <BEA-002613> <Channel "Default[3]" is now listening on 0:0:0:0:0:0:0:1:17001 for protocols iiop, t3, ldap, snmp, http.> <Sep 11, 2019 10:59:06 AM CST> <Notice> <Server> <BEA-002613> <Channel "Default[2]" is now listening on 127.0.0.1:17001 for protocols iiop, t3, ldap, snmp, http.> <Sep 11, 2019 10:59:06 AM CST> <Notice> <Server> <BEA-002613> <Channel "Default[1]" is now listening on fe80:0:0:0:250:56ff:fe96:d83:17001 for protocols iiop, t3, ldap, snmp, http.> <Sep 11, 2019 10:59:06 AM CST> <Notice> <Server> <BEA-002613> <Channel "Default" is now listening on 172.16.2.174:17001 for protocols iiop, t3, ldap, snmp, http.> <Sep 11, 2019 10:59:06 AM CST> <Notice> <WebLogicServer> <BEA-000329> <Started WebLogic Admin Server "AdminServer" for domain "invoice_domain" running in Production Mode> <Sep 11, 2019 10:59:06 AM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RUNNING> <Sep 11, 2019 10:59:06 AM CST> <Notice> <WebLogicServer> <BEA-000360> <Server started in RUNNING mode> <Sep 11, 2019 10:59:07 AM CST> <Notice> <Stdout> <BEA-000000> <注销服务{org.springframework.beans.factory.xml.NamespaceHandlerResolver}={spring.osgi.core.bundle.id=422, spring.osgi.core.bundle.timestamp=1568170745417, service.id=22}> <Sep 11, 2019 10:59:07 AM CST> <Notice> <Stdout> <BEA-000000> <注销服务{org.xml.sax.EntityResolver}={spring.osgi.core.bundle.id=422, spring.osgi.core.bundle.timestamp=1568170745417, service.id=23}> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <Exception in thread "OSGiStartLog Timer" java.lang.ExceptionInInitializerError> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at com.ygsoft.ecp.service.osgi.starter.core.OSGiStartLogTimerTask.run(OSGiStartLogTimerTask.java:54)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at java.util.TimerThread.mainLoop(Timer.java:512)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at java.util.TimerThread.run(Timer.java:462)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <Caused by: org.apache.commons.logging.LogConfigurationException: java.lang.NoClassDefFoundError: sun/reflect/ConstructorAccessorImpl (Caused by java.lang.NoClassDefFoundError: sun/ref lect/ConstructorAccessorImpl)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:637)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:336)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:310)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at com.ygsoft.ecp.service.osgi.starter.util.WebLogicUtil.<clinit>(WebLogicUtil.java:27)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <... 3 more> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <Caused by: java.lang.NoClassDefFoundError: sun/reflect/ConstructorAccessorImpl> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at sun.misc.Unsafe.defineClass(Native Method)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at sun.reflect.ClassDefiner.defineClass(ClassDefiner.java:45)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:381)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at java.security.AccessController.doPrivileged(Native Method)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at sun.reflect.MethodAccessorGenerator.generate(MethodAccessorGenerator.java:377)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at sun.reflect.MethodAccessorGenerator.generateConstructor(MethodAccessorGenerator.java:76)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:30)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at java.lang.reflect.Constructor.newInstance(Constructor.java:513)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:608)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <... 7 more> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <Caused by: java.lang.ClassNotFoundException: BundleLoader[org.apache.commons.logging_1.1.1].loadBundleClass(sun.reflect.ConstructorAccessorImpl)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:407)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:387)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at java.lang.ClassLoader.loadClass(ClassLoader.java:247)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <... 17 more> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <Caused by: java.lang.ClassNotFoundException: sun.reflect.ConstructorAccessorImpl> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:491)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:404)> <Sep 11, 2019 11:04:06 AM CST> <Notice> <StdErr> <BEA-000000> <... 20 more> <Sep 11, 2019 11:09:06 AM CST> <Notice> <StdErr> <BEA-000000> <Exception in thread "OSGiStartLog Timer" java.lang.NoClassDefFoundError: Could not initialize class com.ygsoft.ecp.service.osgi.starter.util.WebLogicUtil> <Sep 11, 2019 11:09:06 AM CST> <Notice> <StdErr> <BEA-000000> <at com.ygsoft.ecp.service.osgi.starter.core.OSGiStartLogTimerTask.run(OSGiStartLogTimerTask.java:54)> <Sep 11, 2019 11:09:06 AM CST> <Notice> <StdErr> <BEA-000000> <at java.util.TimerThread.mainLoop(Timer.java:512)> <Sep 11, 2019 11:09:06 AM CST> <Notice> <StdErr> <BEA-000000> <at java.util.TimerThread.run(Timer.java:462)> <Sep 11, 2019 11:10:24 AM CST> <Warning> <netuix> <BEA-423420> <Redirect is executed in begin or refresh action. Redirect url is /console/console.portal?_nfpb=true&_pageLabel=JdbcDatasourcesJDBCDataSourceConfigTabPage&JdbcDatasourcesJDBCDataSourc eConfigPortlethandle=com.bea.console.handles.JMXHandle%28%22com.bea%3AName%3DJDBC+Data+Source-1%2CType%3Dweblogic.j2ee.descriptor.wl.JDBCDataSourceBean%2CParent%3D%5Binvoice_domain%5D%2FJDBCSystemResources%5BJDBC+Data+Source-1%5D%2CPath%3DJDBCRes ource%5BJDBC+Data+Source-1%5D%22%29.> <Sep 11, 2019 11:14:06 AM CST> <Notice> <StdErr> <BEA-000000> <Exception in thread "OSGiStartLog Timer" java.lang.NoClassDefFoundError: Could not initialize class com.ygsoft.ecp.service.osgi.starter.util.WebLogicUtil> <Sep 11, 2019 11:14:06 AM CST> <Notice> <StdErr> <BEA-000000> <at com.ygsoft.ecp.service.osgi.starter.core.OSGiStartLogTimerTask.run(OSGiStartLogTimerTask.java:54)> <Sep 11, 2019 11:14:06 AM CST> <Notice> <StdErr> <BEA-000000> <at java.util.TimerThread.mainLoop(Timer.java:512)> <Sep 11, 2019 11:14:06 AM CST> <Notice> <StdErr> <BEA-000000> <at java.util.TimerThread.run(Timer.java:462)> <Sep 11, 2019 2:21:40 PM CST> <Warning> <netuix> <BEA-423420> <Redirect is executed in begin or refresh action. Redirect url is /console/console.portal?_nfpb=true&_pageLabel=JdbcDatasourcesJDBCDataSourceConfigTabPage&JdbcDatasourcesJDBCDataSource ConfigPortlethandle=com.bea.console.handles.JMXHandle%28%22com.bea%3AName%3DJDBC+Data+Source-1%2CType%3Dweblogic.j2ee.descriptor.wl.JDBCDataSourceBean%2CParent%3D%5Binvoice_domain%5D%2FJDBCSystemResources%5BJDBC+Data+Source-1%5D%2CPath%3DJDBCReso urce%5BJDBC+Data+Source-1%5D%22%29.> <Sep 11, 2019 3:19:01 PM CST> <Error> <JDBC> <BEA-001112> <Test "SELECT 1 FROM DUAL" set up for pool "JDBC Data Source-1" failed with exception: "java.lang.NullPointerException".> <Sep 11, 2019 3:19:02 PM CST> <Notice> <Stdout> <BEA-000000> <tcp connect from (172.16.2.174:55154) to (172.16.7.3:18600) take 0 seconds for test ok, from nari―jdbc> <Sep 11, 2019 3:19:02 PM CST> <Notice> <Stdout> <BEA-000000> <tcp connect from (172.16.2.174:55155) to (172.16.7.3:18600) take 0 seconds for test ok, from nari―jdbc> ```

SpringMVC+mybatis动态切换数据源,多数据库语言databaseId无效怎么解决。

1、采用SpringMVC+mybatis 2、动态切换数据源实现,单独测试有效 ``` public class DataSources extends AbstractRoutingDataSource{ @Override protected Object determineCurrentLookupKey() { return DataSourceSwitch.getDataSourceType(); } } ``` 3、Mybatis不同数据库语言支持实现,单独测试有效 ``` <!--支持多类型数据库配置--> <bean id="vendorProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="properties"> <props> <prop key="Oracle">oracle</prop> <prop key="MySQL">mysql</prop> </props> </property> </bean> <bean id="databaseIdProvider" class="org.apache.ibatis.mapping.VendorDatabaseIdProvider"> <property name="properties" ref="vendorProperties" /> </bean> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dynamicDataSource" /> <property name="databaseIdProvider" ref="databaseIdProvider" /> <property name="configLocation" value="classpath:mybatis-config.xml"></property> ………… <select id="getTime" resultType="java.lang.String" databaseId="oracle"> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual </select> <select id="getTime" resultType="java.lang.String" databaseId="mysql"> select now() </select> ``` 4、动态切换数据源之后再访问带有databaseId的dao方法就无效了。 5、看SqlSessionFactoryBean源码,databaseId相关代码如下 ``` if (this.databaseIdProvider != null) { try { configuration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource)); } catch (SQLException var24) { throw new NestedIOException("Failed getting a databaseId", var24); } } public String getDatabaseId(DataSource dataSource) { if (dataSource == null) { throw new NullPointerException("dataSource cannot be null"); } else { try { return this.getDatabaseName(dataSource); } catch (Exception var3) { log.error("Could not get a databaseId from dataSource", var3); return null; } } } ``` 断点跟踪代码,只有启动服务的时候执行一次,切换数据源不执行,跪求求高手告知解决办法。献出全部C币。

spring boot使用druid数据源配置错了但是程序还能成功启动,为什么?

spring boot 1.15版本 druid 1.1.0版本 在Application.yml中加上了 validation-query 在发布程序时才发现,我明明写错了数据库密码,但是服务却正常启动了,因为密码错误程序多次尝试连接数据库,结果把数据库账号给锁住了。 有没有一种解决办法,在程序启动时,不能成功连接数据库,禁止程序启动?

使用springcloud 和 连接池 连接orcale数据库报错,折磨一天了,请大佬解救,启动都正常的

数据库使用PLsql可以连接上,ping数据库主机也是通的。找了一天问题了,求大佬解救一下。基本可以排除数据库问题,现在迷了一天了,想早点下班。。。 报错信息: 2018-12-28 17:00:06.350 ERROR 21560 --- [http-nio-9661-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.lang.NullPointerException at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:289) ~[spring-jdbc-4.3.12.RELEASE.jar:4.3.12.RELEASE] at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373) ~[spring-tx-4.3.12.RELEASE.jar:4.3.12.RELEASE] at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:447) ~[spring-tx-4.3.12.RELEASE.jar:4.3.12.RELEASE] at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:277) ~[spring-tx-4.3.12.RELEASE.jar:4.3.12.RELEASE] at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.12.RELEASE.jar:4.3.12.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE] at grp.pt.common.bs.CacheService$$EnhancerBySpringCGLIB$$14ccc726.putMap(<generated>) ~[grp-util-com-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at grp.pt.util.PublicSessionUtil.createSession(PublicSessionUtil.java:118) ~[grp-util-com-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at grp.pt.util.PublicSessionUtil.initSessionInfo(PublicSessionUtil.java:39) ~[grp-util-com-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at grp.util.session.UserSessionFilter.doFilter(UserSessionFilter.java:41) ~[grp-util-com-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:108) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.23.jar:8.5.23] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_144] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_144] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.23.jar:8.5.23] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_144] Caused by: java.lang.NullPointerException: null at grp.pt.util.PublicSessionUtil.getDataSourceBeanKey(PublicSessionUtil.java:138) ~[grp-util-com-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at grp.pt.database.DynamicDataSource.determineCurrentLookupKey(DynamicDataSource.java:21) ~[grp-database-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource.determineTargetDataSource(AbstractRoutingDataSource.java:196) ~[spring-jdbc-4.3.12.RELEASE.jar:4.3.12.RELEASE] at org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource.getConnection(AbstractRoutingDataSource.java:164) ~[spring-jdbc-4.3.12.RELEASE.jar:4.3.12.RELEASE] at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:246) ~[spring-jdbc-4.3.12.RELEASE.jar:4.3.12.RELEASE] ... 46 common frames omitted yml数据库配置内容 ``` dynamicdata: #系统运行模式[Develop, Product] mode: Develop #默认数据源 defaultKey: admdiv jndiName: data-sources: #数据源名: admdiv_年度_区划code admdiv: driverClassName: oracle.jdbc.driver.OracleDriver #url: jdbc:oracle:thin:@localhost:1521:orcl #driverClassName: com.mysql.jdbc.Driver #连接URL,协议+地址+Scheme #url: jdbc:mysql://localhost:3306/gap_ah?useUnicode=true&characterEncoding=utf8&useSSL=false username: yszx2018 #密码 password: a #数据库连接池配置样例 url: jdbc:oracle:thin:@localhost:1521:orcl #连接池的最大连接数,-1为无限制 maxActive: 8 #最大空闲连接数,-1为无限制。注:如果是高负载系统,此值过低时可能会出现连接关闭的同时会打开新连接,连接池失效 maxIdle: 8 #在连接池满的情况下最长等待时间(毫秒),如果超时则抛异常,-1为一直等待 maxWait: -1 #初始连接数 initialSize: 8 #自动回收超时连接 removeAbandoned: true #自动回收超时时间(以秒数为单位) removeAbandonedTimeout: 3600000 #是否要进行检测 testWhileIdle: true #进行检测一个连接是有效的SQL语句,比如oracle是select 1 from dual 而 mysql是 select 1 validationQuery: select 1 from dual #每隔多少时间检测一次,比如每半小时检测一次,总不能总是检测,这会对性能产生影响 timeBetweenEvictionRunsMillis: 180000 #每次检测时,需要检测多少个数据连接,一般设置为与最大连接数一样,这样就可以检测完所有的连接 numTestsPerEvictionRun: 8 #一个数据库连接连接多少时间之外,我们认为其应该不再适用了(可能下一次就会失效了),应该移除并重新建立连接了 minEvictableIdleTimeMillis: 3600000 ```

ssm框架使用注解注入失败

![图片说明](https://img-ask.csdn.net/upload/201605/27/1464332870_733703.png) <!-- 加载db.properties文件中的内容,db.properties文件中的key要有一定的特殊规则 --> <context:property-placeholder location="classpath:jdbc.properties"/> <!-- 扫描标注@Repository注解的service --> <context:component-scan base-package="cn.bdqn.ssm.service.impl.*"/> <!--数据源配置 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" > <property name="url" value="${jdbc.url}"></property> <property name="username" value="${jdbc.username}"></property> <property name="password" value="${jdbc.password}"></property> <property name="driverClassName" value="${jdbc.driverClass}"></property> </bean> <!-- SessionFactory配置 --> <!-- 配置SqlSessionFactory ,整合spring和MyBatis,使其完美结合--> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 数据源 --> <property name="dataSource" ref="dataSource"/> <!-- 自动扫描entity目录,省掉手动配置映射文件--> <property name="mapperLocations" value="classpath:cn/bdqn/ssm/mapping/*.xml" /> </bean> <!-- 配置Mapper扫描器 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!-- 扫描包路径,如果需要扫描多个包中间用半角逗号隔开 --> <property name="basePackage" value="cn.bdqn.ssm.dao"/> <!-- 这边不能使用ref="sqlSessionFactory"原因是因为上面加载配置文件导致这边引用会报错 --> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> </bean> <!-- 事务管理器 对mybatis操作数据库事务控制,spring使用jdbc的事务控制类 --> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!-- <property name="sqlSessionFactoryBeanName" ref="sqlSessionFactory"></property> --> <!-- 数据源 dataSource在applicationContext-dao.xml中配置了 --> <property name="dataSource" ref="dataSource" /> </bean> <!-- 配置事务增强 --> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="registe*" propagation="REQUIRED"/> <tx:method name="insert*" propagation="REQUIRED"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="del*" propagation="REQUIRED"/> <tx:method name="delete*" propagation="REQUIRED"/> <tx:method name="remove*" propagation="REQUIRED"/> <tx:method name="add*" propagation="REQUIRED"/> <tx:method name="save*" propagation="REQUIRED"/> <tx:method name="modify*" propagation="REQUIRED"/> <tx:method name="find*" read-only="true"/> <tx:method name="get*" read-only="true"/> <tx:method name="load*" read-only="true"/> <tx:method name="login*" read-only="true"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut expression="execution(* cn.bdqn.ssm.service.impl.*.*(..))" id="pointCut"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="pointCut"/> </aop:config> </beans>

apringtask项目使用ssm框架但是并没有使用到mvc项目运行后报很多错 是配置文件有问题嚒

//这是spring-mybatis配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 开启注解配置 --> <context:annotation-config /> <!-- 把SqlSessionFactory交给spring管理 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 注入数据源 --> <property name="dataSource" ref="dataSource"/> <!-- 注入mybatis配置文件路径 --> <property name="configLocation" value="classpath:mybatis-config.xml" /> <!-- 注入映射文件 mapper/*.xml --> <property name="mapperLocations" value="classpath:com/zznode/qoe/task/mapper/*.xml"></property> </bean> <context:property-placeholder location="classpath:db.properties" ignore-unresolvable="true"/> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <!--initialSize: 初始化连接--> <property name="initialSize" value="5"/> <!--maxIdle: 最大空闲连接--> <property name="maxIdle" value="10"/> <!--minIdle: 最小空闲连接--> <property name="minIdle" value="5"/> <!--maxActive: 最大连接数量--> <property name="maxActive" value="50"/> <!--removeAbandoned: 是否自动回收超时连接--> <property name="removeAbandoned" value="true"/> <!--removeAbandonedTimeout: 超时时间(以秒数为单位)--> <property name="removeAbandonedTimeout" value="300"/> <!--maxWait: 超时等待时间以毫秒为单位 6000毫秒/1000等于60秒--> <property name="maxWait" value="3000"/> <property name="validationQuery" value="SELECT 1" /> <property name="testOnBorrow" value="true"/> </bean> <!-- 事务管理 transaction manager, use JtaTransactionManager for global tx --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!-- 配置事务拦截器和传播属性 --> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager" ref="transactionManager" /> <property name="transactionAttributes"> <props> <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="list*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="query*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="submit*">PROPAGATION_REQUIRED</prop> <prop key="create*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="update*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="modify*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="remove*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="do*">PROPAGATION_REQUIRED</prop> <prop key="execute*">PROPAGATION_REQUIRED</prop> <prop key="exe*">PROPAGATION_REQUIRED</prop> <prop key="backup">PROPAGATION_REQUIRED,-Exception</prop> <prop key="rollback">PROPAGATION_REQUIRED,-Exception</prop> <prop key="calculate">PROPAGATION_REQUIRED,-Exception</prop> <prop key="batchInsert">PROPAGATION_REQUIRED,-Exception</prop> <prop key="batchUpdate">PROPAGATION_REQUIRED,-Exception</prop> </props> </property> </bean> <!-- Mapper接口所在包名,Spring会自动查找其下的Mapper 不用再配置mapper扫描--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.zznode.qoe.task.mapper" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> </bean> </beans> ``` 报错如下: 01-Apr-2019 10:56:58.839 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 01-Apr-2019 10:56:58.930 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.context.ContextLoader.initWebApplicationContext Root WebApplicationContext: initialization started 01-Apr-2019 10:56:59.219 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.context.support.XmlWebApplicationContext.prepareRefresh Refreshing Root WebApplicationContext: startup date [Mon Apr 01 10:56:59 CST 2019]; root of context hierarchy 01-Apr-2019 10:56:59.324 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from class path resource [spring.xml] 01-Apr-2019 10:56:59.632 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from class path resource [spring-mybatis.xml] 01-Apr-2019 10:56:59.682 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from class path resource [jobs.xml] 01-Apr-2019 10:57:00.297 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from class path resource [spring-mybatis.xml] 01-Apr-2019 10:57:00.694 璀﹀憡 [RMI TCP Connection(2)-127.0.0.1] org.mybatis.spring.mapper.ClassPathMapperScanner.checkCandidate Skipping MapperFactoryBean with name 'mtMonitorServerInfoMapper' and 'com.zznode.qoe.task.mapper.MtMonitorServerInfoMapper' mapperInterface. Bean already defined with the same name! 01-Apr-2019 10:57:00.697 璀﹀憡 [RMI TCP Connection(2)-127.0.0.1] org.mybatis.spring.mapper.ClassPathMapperScanner.checkCandidate Skipping MapperFactoryBean with name 'mtServerAlarmMapper' and 'com.zznode.qoe.task.mapper.MtServerAlarmMapper' mapperInterface. Bean already defined with the same name! 01-Apr-2019 10:57:00.697 璀﹀憡 [RMI TCP Connection(2)-127.0.0.1] org.mybatis.spring.mapper.ClassPathMapperScanner.checkCandidate Skipping MapperFactoryBean with name 'newTbResultMapper' and 'com.zznode.qoe.task.mapper.NewTbResultMapper' mapperInterface. Bean already defined with the same name! 01-Apr-2019 10:57:00.698 璀﹀憡 [RMI TCP Connection(2)-127.0.0.1] org.mybatis.spring.mapper.ClassPathMapperScanner.checkCandidate Skipping MapperFactoryBean with name 'sysAuthInfoMapper' and 'com.zznode.qoe.task.mapper.SysAuthInfoMapper' mapperInterface. Bean already defined with the same name! 01-Apr-2019 10:57:00.703 璀﹀憡 [RMI TCP Connection(2)-127.0.0.1] org.mybatis.spring.mapper.ClassPathMapperScanner.checkCandidate Skipping MapperFactoryBean with name 'sysMailUserInfoMapper' and 'com.zznode.qoe.task.mapper.SysMailUserInfoMapper' mapperInterface. Bean already defined with the same name! 01-Apr-2019 10:57:00.706 璀﹀憡 [RMI TCP Connection(2)-127.0.0.1] org.mybatis.spring.mapper.ClassPathMapperScanner.checkCandidate Skipping MapperFactoryBean with name 'sysMonitorServerAttrMapper' and 'com.zznode.qoe.task.mapper.SysMonitorServerAttrMapper' mapperInterface. Bean already defined with the same name! 01-Apr-2019 10:57:00.707 璀﹀憡 [RMI TCP Connection(2)-127.0.0.1] org.mybatis.spring.mapper.ClassPathMapperScanner.checkCandidate Skipping MapperFactoryBean with name 'sysMonitorServerMapper' and 'com.zznode.qoe.task.mapper.SysMonitorServerMapper' mapperInterface. Bean already defined with the same name! 01-Apr-2019 10:57:00.708 璀﹀憡 [RMI TCP Connection(2)-127.0.0.1] org.mybatis.spring.mapper.ClassPathMapperScanner.checkCandidate Skipping MapperFactoryBean with name 'tbBssUserMapper' and 'com.zznode.qoe.task.mapper.TbBssUserMapper' mapperInterface. Bean already defined with the same name! 01-Apr-2019 10:57:00.708 璀﹀憡 [RMI TCP Connection(2)-127.0.0.1] org.mybatis.spring.mapper.ClassPathMapperScanner.checkCandidate Skipping MapperFactoryBean with name 'tbCbssUserMapper' and 'com.zznode.qoe.task.mapper.TbCbssUserMapper' mapperInterface. Bean already defined with the same name! 01-Apr-2019 10:57:00.708 璀﹀憡 [RMI TCP Connection(2)-127.0.0.1] org.mybatis.spring.mapper.ClassPathMapperScanner.checkCandidate Skipping MapperFactoryBean with name 'tbDistributionMapper' and 'com.zznode.qoe.task.mapper.TbDistributionMapper' mapperInterface. Bean already defined with the same name! 01-Apr-2019 10:57:00.709 璀﹀憡 [RMI TCP Connection(2)-127.0.0.1] org.mybatis.spring.mapper.ClassPathMapperScanner.checkCandidate Skipping MapperFactoryBean with name 'tbresultMapper' and 'com.zznode.qoe.task.mapper.TbresultMapper' mapperInterface. Bean already defined with the same name! 01-Apr-2019 10:57:00.709 璀﹀憡 [RMI TCP Connection(2)-127.0.0.1] org.mybatis.spring.mapper.ClassPathMapperScanner.checkCandidate Skipping MapperFactoryBean with name 'tbSpeedUserCountMapper' and 'com.zznode.qoe.task.mapper.TbSpeedUserCountMapper' mapperInterface. Bean already defined with the same name! 01-Apr-2019 10:57:00.710 璀﹀憡 [RMI TCP Connection(2)-127.0.0.1] org.mybatis.spring.mapper.ClassPathMapperScanner.checkCandidate Skipping MapperFactoryBean with name 'tbUploadFileInfoMapper' and 'com.zznode.qoe.task.mapper.TbUploadFileInfoMapper' mapperInterface. Bean already defined with the same name! 01-Apr-2019 10:57:00.711 璀﹀憡 [RMI TCP Connection(2)-127.0.0.1] org.mybatis.spring.mapper.ClassPathMapperScanner.checkCandidate Skipping MapperFactoryBean with name 'tbWordbookMapper' and 'com.zznode.qoe.task.mapper.TbWordbookMapper' mapperInterface. Bean already defined with the same name! 01-Apr-2019 10:57:00.711 璀﹀憡 [RMI TCP Connection(2)-127.0.0.1] org.mybatis.spring.mapper.ClassPathMapperScanner.doScan No MyBatis mapper was found in '[com.zznode.qoe.task.mapper]' package. Please check your configuration. 01-Apr-2019 10:57:00.745 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PropertySourcesPlaceholderConfigurer.loadProperties Loading properties file from class path resource [db.properties] 01-Apr-2019 10:57:00.760 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PropertySourcesPlaceholderConfigurer.loadProperties Loading properties file from class path resource [config.properties] 01-Apr-2019 10:57:00.767 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PropertySourcesPlaceholderConfigurer.loadProperties Loading properties file from class path resource [db.properties] 01-Apr-2019 10:57:00.929 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'dataSource' of type [class org.apache.commons.dbcp.BasicDataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 01-Apr-2019 10:57:01.671 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'sqlSessionFactory' of type [class org.mybatis.spring.SqlSessionFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 01-Apr-2019 10:57:01.672 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'sqlSessionFactory' of type [class org.apache.ibatis.session.defaults.DefaultSqlSessionFactory] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 01-Apr-2019 10:57:01.684 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'mtMonitorServerInfoMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 01-Apr-2019 10:57:01.686 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'mtServerAlarmMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 01-Apr-2019 10:57:01.688 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'newTbResultMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 01-Apr-2019 10:57:01.691 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'sysAuthInfoMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 01-Apr-2019 10:57:01.694 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'sysMailUserInfoMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 01-Apr-2019 10:57:01.695 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'sysMonitorServerAttrMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 01-Apr-2019 10:57:01.697 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'sysMonitorServerMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 01-Apr-2019 10:57:01.699 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'tbBssUserMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 01-Apr-2019 10:57:01.703 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'tbCbssUserMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 01-Apr-2019 10:57:01.707 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'tbDistributionMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 01-Apr-2019 10:57:01.710 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'tbresultMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 01-Apr-2019 10:57:01.714 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'tbSpeedUserCountMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 01-Apr-2019 10:57:01.715 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'tbUploadFileInfoMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 01-Apr-2019 10:57:01.717 淇℃伅 [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'tbWordbookMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 01-Apr-2019 10:57:02.421 璀﹀憡 [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.context.support.XmlWebApplicationContext.refresh Exception encountered during context initialization - cancelling refresh attempt org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hbServerMonitoJob' defined in file [E:\ZHIZHEN\springtask\springtask\target\spring-task\WEB-INF\classes\com\zznode\qoe\task\control\HbServerMonitoJob.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zznode.qoe.task.control.HbServerMonitoJob]: Constructor threw exception; nested exception is java.lang.NullPointerException at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1105) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ```

我的jsp程序用junit测试数据显示正确,但是用在jsp页面显示空指针异常

程序如下: ``` <% List<Emp> list=new EmpDao().findAll(); for (Emp emp : list) { out.print(emp.getEmpno()+" "+emp.getEname()+" "+emp.getHireDate()+" "+emp.getSal()+"<br/>"); } %> ``` 显示异常: ``` org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 35 32: response.addCookie(c1); 33: response.addCookie(c2); 34: response.sendRedirect("cookie.jsp"); */ 35: List<Emp> list=new EmpDao().findAll(); 36: for (Emp emp : list) { 37: out.print(emp.getEmpno()+" "+emp.getEname()+" "+emp.getHireDate()+" "+emp.getSal()+"<br/>"); 38: } Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:588) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:481) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) root cause java.lang.NullPointerException dao.BaseDao.excuteFind(BaseDao.java:23) dao.EmpDao.findAll(EmpDao.java:14) org.apache.jsp.index_jsp._jspService(index_jsp.java:153) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ``` 检查无法获得连接,可是我用junit取得的连接是正常的,这怎么搞? basedao程序 ``` package cn.anywhere.dao; import java.io.*; import java.sql.*; import java.util.Properties; import java.sql.DriverManager; import cn.anywhere.util.DatabaseConnection; public class BaseDAO { protected PreparedStatement pstmt = null; protected ResultSet rs = null; protected static Properties properties=null; protected static Connection connection = null; public ResultSet findAll(String sql){ try{ connection=DatabaseConnection.getConnection(); pstmt=connection.prepareStatement(sql); rs=pstmt.executeQuery(); return rs; } catch (SQLException e){ e.printStackTrace(); } return rs; } } ``` 显示的异常是connection异常.我怀疑是我的oracle jdbc文件没放对位置.因为java程序我在biuld path里加载oracle7.jar文件做连接.但是JSP程序的oracle jdbc文件应该放哪个目录? 我的项目目录结构是这样的 ![图片说明](https://img-ask.csdn.net/upload/201704/20/1492699458_461238.jpg)

hikari数据库连接池问题

spring: http: encoding.charset: UTF-8 encoding.enable: true encoding.force: true datasource: name: hikari driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/test username: root password: 123456 # hikari type: com.zaxxer.hikari.HikariDataSource maximum-pool-size: 100 max-idle: 10 max-wait: 10000 min-idle: 5 initial-size: 5 validation-query: SELECT 1 test-on-borrow: false test-while-idle: true time-between-eviction-runs-millis: 18800 第一次启动成功了,没报错,项目也能正常访问了,可是后面更新了项目重新启动之后就一直报错: org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [HikariDataSource (HikariPool-0)] with key 'dataSource'; nested exception is javax.management.InstanceAlreadyExistsException: com.zaxxer.hikari:name=dataSource,type=HikariDataSource 这是说实例已经存在了吗,这个问题要怎么解决呢

SSH框架中的有关数据库的问题

我其他没有问题,就是连接数据库可能有问题,但是程序也能初始化成功,但在执行具体sql的时候,不能执行 [b]java.lang.NullPointerException at com.test.dao.BaseDaoImpl.loadObject(BaseDaoImpl.java:29) at com.test.service.impl.UserServiceImpl.selectUserByNumber(UserServiceImpl.java:38) at com.test.struts.action.UserAction.selectUserByNumber(UserAction.java:90) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243) at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.test.struts.interceptor.LoggerInterceptor.intercept(LoggerInterceptor.java:42) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.TimerInterceptor.invokeUnderTiming(TimerInterceptor.java:124) at com.opensymphony.xwork2.interceptor.TimerInterceptor.intercept(TimerInterceptor.java:111) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Unknown Source)[/b] 这是我的其中spring和hibernate的配置文件 [code="java"] <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- 开启注解处理器 --> <context:annotation-config/> <!-- 定义使用C3P0连接池的数据源 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <!-- 指定连接数据库的JDBC驱动 --> <property name="driverClass"> <value>com.mysql.jdbc.Driver</value> </property> <!-- 连接数据库所用的URL --> <property name="jdbcUrl"> <value>jdbc:mysql://localhost:3306/softtest?useUnicode=true&amp;characterEncoding=utf-8</value> </property> <!-- 连接数据库的用户名 --> <property name="user"> <value>root</value> </property> <!-- 连接数据库的密码 --> <property name="password"> <value>root</value> </property> <!-- 设置数据库连接池的最大连接数 --> <property name="maxPoolSize"> <value>20</value> </property> <!-- 设置数据库连接池的最小连接数 --> <property name="minPoolSize"> <value>2</value> </property> <!-- 设置数据库连接池的初始化连接数 --> <property name="initialPoolSize"> <value>2</value> </property> <!-- 设置数据库连接池的连接的最大空闲时间,单位为秒 --> <property name="maxIdleTime"> <value>20</value> </property> </bean> <!-- 定义Hibernate的SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <!-- 依赖注入上面定义的数据源dataSource --> <property name="dataSource" ref="dataSource"/> <!-- 注册Hibernate的ORM映射文件 --> <property name="mappingResources"> <list> <value>com/test/orm/FaultInfo.hbm.xml</value> <value>com/test/orm/ModelInfo.hbm.xml</value> <value>com/test/orm/ProjectInfo.hbm.xml</value> <value>com/test/orm/UserInfo.hbm.xml</value> <value>com/test/orm/UserModel.hbm.xml</value> <value>com/test/orm/UserFault.hbm.xml</value> <value>com/test/orm/UserProject.hbm.xml</value> <value>com/test/orm/FaultType.hbm.xml</value> <value>com/test/orm/Logger.hbm.xml</value> </list> </property> <!-- 设置Hibernate的相关属性 --> <property name="hibernateProperties"> <props> <!-- 设置Hibernate的数据库方言 --> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <!-- 设置Hibernate是否在控制台输出SQL语句,开发调试阶段通常设为true --> <prop key="show_sql">true</prop> <!-- 设置Hibernate一个提交批次中的最大SQL语句数 --> <prop key="hibernate.jdbc.batch_size">50</prop> </props> </property> </bean> <!--定义Hibernate的事务管理器HibernateTransactionManager --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <!-- 依赖注入上面定义的sessionFactory --> <property name="sessionFactory" ref="sessionFactory"/> </bean> <!-- 装配HibernateTemplate实例 --> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <constructor-arg ref="sessionFactory"/> </bean> </beans> [/code] 这是我的数据库操作代码 [code="java"] public Object loadObject(String hql) { final String hql1 = hql; Object obj = null; try { List list = hibernateTemplate.executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Query query = session.createQuery(hql1); return query.list(); } }); if (list.size() > 0) { obj = list.get(0); } } catch (Exception e) { e.printStackTrace(); } return obj; } [/code]

Spring 3.0+ Hibernate 3.3 泛型 注解管理Bean 出现问题 郁闷!

参照网上的Demo 自己也弄了个泛型注解 BaseDao 里面 的gedao 是null 高手们给看一下 [code="java"]package com.zw.core; import java.io.Serializable; import java.util.List; public interface IBaseDao<T, PK extends Serializable> { public T getById(PK id); public List<T> getAll(); public T load(PK id); public void load(T entityObject, PK id); public void delete(T entityObject); public void deleteById(PK id); public void refresh(T entityObject); public void evict(T entityObject); public void save(T entityObject); public void clear(); }[/code] [code="java"]package com.zw.core; import java.io.Serializable; import java.util.List; public class BaseDao<T, PK extends Serializable> implements IBaseDao<T, PK> { protected Class<T> entityClass;// DAO所管理的Entity类型. private GenericEntityDao<T, PK> gedao; public Class<T> getEntityClass() { return entityClass; } public void setEntityClass(Class<T> entityClass) { this.entityClass = entityClass; } public GenericEntityDao<T, PK> getGedao() { return gedao; } public void setGedao(GenericEntityDao<T, PK> gedao) { this.gedao = gedao; } /** * 让spring提供构造函数注入 */ public BaseDao(Class<T> type) { this.entityClass = type; } public BaseDao() { } public void delete(T entityObject) { gedao.delete(entityObject); } public void deleteById(PK id) { gedao.deleteById(id); } public void evict(T entityObject) { gedao.evict(entityObject); } public List<T> getAll() { return gedao.getAll(); } public T getById(PK id) { return gedao.getById(id); } public T load(PK id) { return gedao.load(id); } public void load(T entityObject, PK id) { gedao.load(entityObject, id); } public T merge(T entityObject) { return gedao.merge(entityObject); } public void refresh(T entityObject) { gedao.refresh(entityObject); } public void save(T entityObject) { System.out.println("gedao:"+gedao); gedao.save(entityObject); } public void clear() { } } [/code] [code="java"]package com.zw.core; import java.io.Serializable; import java.util.List; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; public class GenericEntityDao<T, PK extends Serializable> extends HibernateDaoSupport { protected Class<T> entityClass;// DAO所管理的Entity类型. public GenericEntityDao() { } public GenericEntityDao(Class<T> entityClass) { this.entityClass = entityClass; } @SuppressWarnings("unchecked") public T getById(PK id) { return (T) this.getHibernateTemplate().get(this.entityClass, id); } @SuppressWarnings("unchecked") public List<T> getAll() { return (List<T>) (this.getHibernateTemplate().loadAll(this.entityClass)); } @SuppressWarnings("unchecked") public T load(PK id) { return (T) this.getHibernateTemplate().load(this.entityClass, id); } public void load(T entityObject, PK id) { this.getHibernateTemplate().load(entityObject, id); } public void delete(T entityObject) { this.getHibernateTemplate().delete(entityObject); } public void deleteById(PK id) { this.delete(this.getById(id)); } public void refresh(T entityObject) { this.getHibernateTemplate().refresh(entityObject); } public void evict(T entityObject) { this.getHibernateTemplate().evict(entityObject); } public void save(T entityObject) { this.getHibernateTemplate().saveOrUpdate(entityObject); } @SuppressWarnings("unchecked") public T merge(T entityObject) { return (T) this.getHibernateTemplate().merge(entityObject); } } [/code] ToplMSoftDAO [code="java"]package com.zw.dao; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.stereotype.Repository; import com.zw.core.BaseDao; import com.zw.domain.ToplMSoft; @Repository("toplMSoftDAO") public class ToplMSoftDAO extends BaseDao<ToplMSoft,Integer> { private static final Log log = LogFactory.getLog(ToplMSoftDAO.class); } [/code] [code="java"] <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <!-- 使用外部文件配置数据源的属性 --> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <!-- 外部文件地址 --> <value>classpath:database_conn.properties </value> </list> </property> <property name="fileEncoding" value="utf-8" /> </bean> <!-- 配置数据源 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="${driverClassName}" /> <property name="jdbcUrl" value="${url}" /> <property name="user" value="${username}" /> <property name="password" value="${password}" /> <property name="minPoolSize" value="5" /> <property name="maxPoolSize" value="20" /> <property name="initialPoolSize" value="10" /> <property name="maxIdleTime" value="60" /> <property name="acquireIncrement" value="5" /> <property name="maxStatements" value="0" /> <property name="idleConnectionTestPeriod" value="60" /> <property name="acquireRetryAttempts" value="30" /> <property name="breakAfterAcquireFailure" value="true" /> <property name="testConnectionOnCheckout" value="false" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <!-- 引用数据源 --> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="namingStrategy"> <bean class="org.hibernate.cfg.ImprovedNamingStrategy" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect </prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="hibernate.jdbc.fetch_size">${hibernate.jdbc.fetch_size} </prop> <prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size} </prop> </props> </property> <property name="packagesToScan" value="com.zw.domain" /> <!--</property> <property name="annotatedClasses"> <list> <value>org.wpms.kernel.user.po.User</value> </list> </property>--> </bean> <!-- 定义了与实体相关的dao --> <bean id="genericEntityDao" class="com.zw.core.GenericEntityDao" scope="prototype" lazy-init="true"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <!--使用泛型DAO作为抽象基类 abstract="true" --> <bean id="baseDao" class="com.zw.core.BaseDao" abstract="true" depends-on="genericEntityDao"> <property name="gedao"> <ref bean="genericEntityDao" /> </property> </bean> <!-- 使Spring关注Annotation --> <context:annotation-config /> <!-- 让Spring通过自动扫描来查询和管理Bean --> <context:component-scan base-package="com.zw" /> <!-- <bean id="toplMSoftDAO" class="com.zw.dao.ToplMSoftDAO" parent="baseDao"></bean> <bean id="toplMSoftServiceImpl" class="com.zw.service.impl.ToplMSoftServiceImpl"> <property name="toplMSoftDAO" ref="toplMSoftDAO" /> </bean> --> <!-- 业务类bean的实现类标注了@Transactional注解,所以会被 tx:annotation-driven注解驱动自动织入事务增强 --> <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <!--注解式事务配置驱动--> <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /> </beans> [/code] ToplMSoft [code="java"] package com.zw.domain; import java.sql.Timestamp; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import static javax.persistence.GenerationType.IDENTITY; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name = "topl_m_soft", catalog = "zwtest") public class ToplMSoft implements java.io.Serializable { // Fields /** * */ private static final long serialVersionUID = -5245203859352468180L; private Integer softkey; private String softname; private String softtypekey; private String softversion; private String softsize; private String providername; private String providersite; private String downsite1; private String softfaceurl; private String issuestate; private String fruntime; private String sruntime; private Float marketprice; private Float storeprice; private String ifourcommend; private String ifspprice; private String softenglishname; private String runLink; private String runnum; private String downnum; private String column1; private String column2; private String column3; private String contact; private Timestamp createdate; private Timestamp updatedate; // Constructors /** default constructor */ public ToplMSoft() { } // Property accessors @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "softkey", unique = true, nullable = false) public Integer getSoftkey() { return this.softkey; } public void setSoftkey(Integer softkey) { this.softkey = softkey; } @Column(name = "softname", nullable = false, length = 100) public String getSoftname() { return this.softname; } public void setSoftname(String softname) { this.softname = softname; } @Column(name = "softtypekey", nullable = false, length = 10) public String getSofttypekey() { return this.softtypekey; } public void setSofttypekey(String softtypekey) { this.softtypekey = softtypekey; } @Column(name = "softversion", length = 20) public String getSoftversion() { return this.softversion; } public void setSoftversion(String softversion) { this.softversion = softversion; } @Column(name = "softsize", length = 20) public String getSoftsize() { return this.softsize; } public void setSoftsize(String softsize) { this.softsize = softsize; } @Column(name = "providername", length = 200) public String getProvidername() { return this.providername; } public void setProvidername(String providername) { this.providername = providername; } @Column(name = "providersite", length = 100) public String getProvidersite() { return this.providersite; } public void setProvidersite(String providersite) { this.providersite = providersite; } @Column(name = "downsite1", length = 300) public String getDownsite1() { return this.downsite1; } public void setDownsite1(String downsite1) { this.downsite1 = downsite1; } @Column(name = "softfaceurl", length = 200) public String getSoftfaceurl() { return this.softfaceurl; } public void setSoftfaceurl(String softfaceurl) { this.softfaceurl = softfaceurl; } @Column(name = "issuestate", length = 10) public String getIssuestate() { return this.issuestate; } public void setIssuestate(String issuestate) { this.issuestate = issuestate; } @Column(name = "fruntime", length = 10) public String getFruntime() { return this.fruntime; } public void setFruntime(String fruntime) { this.fruntime = fruntime; } @Column(name = "sruntime", length = 10) public String getSruntime() { return this.sruntime; } public void setSruntime(String sruntime) { this.sruntime = sruntime; } @Column(name = "marketprice", precision = 10, scale = 0) public Float getMarketprice() { return this.marketprice; } public void setMarketprice(Float marketprice) { this.marketprice = marketprice; } @Column(name = "storeprice", precision = 10, scale = 0) public Float getStoreprice() { return this.storeprice; } public void setStoreprice(Float storeprice) { this.storeprice = storeprice; } @Column(name = "ifourcommend", length = 2) public String getIfourcommend() { return this.ifourcommend; } public void setIfourcommend(String ifourcommend) { this.ifourcommend = ifourcommend; } @Column(name = "ifspprice", length = 2) public String getIfspprice() { return this.ifspprice; } public void setIfspprice(String ifspprice) { this.ifspprice = ifspprice; } @Column(name = "softenglishname", length = 200) public String getSoftenglishname() { return this.softenglishname; } public void setSoftenglishname(String softenglishname) { this.softenglishname = softenglishname; } @Column(name = "runLink", length = 300) public String getRunLink() { return this.runLink; } public void setRunLink(String runLink) { this.runLink = runLink; } @Column(name = "runnum", length = 10) public String getRunnum() { return this.runnum; } public void setRunnum(String runnum) { this.runnum = runnum; } @Column(name = "downnum", length = 10) public String getDownnum() { return this.downnum; } public void setDownnum(String downnum) { this.downnum = downnum; } @Column(name = "column1", nullable = false, length = 2000) public String getColumn1() { return this.column1; } public void setColumn1(String column1) { this.column1 = column1; } @Column(name = "column2", length = 200) public String getColumn2() { return this.column2; } public void setColumn2(String column2) { this.column2 = column2; } @Column(name = "column3", length = 200) public String getColumn3() { return this.column3; } public void setColumn3(String column3) { this.column3 = column3; } @Column(name = "contact", length = 2) public String getContact() { return this.contact; } public void setContact(String contact) { this.contact = contact; } @Column(name = "createdate", length = 19) public Timestamp getCreatedate() { return this.createdate; } public void setCreatedate(Timestamp createdate) { this.createdate = createdate; } @Column(name = "updatedate", length = 19) public Timestamp getUpdatedate() { return this.updatedate; } public void setUpdatedate(Timestamp updatedate) { this.updatedate = updatedate; } } [/code] service 层 ToplMSoftService [code="java"] package com.zw.service; import com.zw.domain.ToplMSoft; public interface ToplMSoftService { public void save(ToplMSoft tps); } [/code] ToplMSoftServiceImpl [code="java"]package com.zw.service.impl; import javax.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import com.zw.core.BaseDao; import com.zw.core.IBaseDao; import com.zw.domain.ToplMSoft; import com.zw.service.ToplMSoftService; @Transactional(readOnly = true) //对业务类进行事务增强的标注 @Service //声明此类为业务逻辑层的类 public class ToplMSoftServiceImpl implements ToplMSoftService { @Resource(name ="toplMSoftDAO") private IBaseDao <ToplMSoft, Integer> toplMSoftDAO; public IBaseDao<ToplMSoft, Integer> getToplMSoftDAO() { return toplMSoftDAO; } public void setToplMSoftDAO(IBaseDao<ToplMSoft, Integer> toplMSoftDAO) { this.toplMSoftDAO = toplMSoftDAO; } @Transactional(readOnly = false, propagation = Propagation.REQUIRED) public void save(ToplMSoft tps) { System.out.println("toplMSoftDAO:"+toplMSoftDAO); this.toplMSoftDAO.save(tps); } } [/code] Test: [code="java"] package com.zw.test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.zw.domain.ToplMSoft; import com.zw.service.ToplMSoftService; import com.zw.service.impl.ToplMSoftServiceImpl; public class TestHibernate { public static void main(String[] args) { ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml"); ToplMSoftService dao= (ToplMSoftServiceImpl) ctx.getBean("toplMSoftServiceImpl"); //GenericEntityDao dao= (GenericEntityDao) ctx.getBean("ToplMSoftDAO"); System.out.println("1111111111:"+dao); ToplMSoft tps=new ToplMSoft(); tps.setSoftname("测试11111111"); tps.setSofttypekey("2"); tps.setColumn1("xsdasdasdasd"); dao.save(tps); } } [/code] 控制台输出 我在BaseDao save方法里面打出 System.out.println("gedao:"+gedao); 为null [code="java"] 1111111111:com.zw.service.impl.ToplMSoftServiceImpl@6e3e5e toplMSoftDAO:com.zw.dao.ToplMSoftDAO@10718b7 gedao:null Exception in thread "main" java.lang.NullPointerException at com.zw.core.BaseDao.save(BaseDao.java:60) at com.zw.service.impl.ToplMSoftServiceImpl.save(ToplMSoftServiceImpl.java:31) at com.zw.service.impl.ToplMSoftServiceImpl$$FastClassByCGLIB$$7aa0faa6.invoke(<generated>) at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191) at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:692) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:625) at com.zw.service.impl.ToplMSoftServiceImpl$$EnhancerByCGLIB$$ded4983e.save(<generated>) at com.zw.test.TestHibernate.main(TestHibernate.java:22) [/code] 如果不用注解 直接在applicationContext.xml配置 [code="java"] <bean id="toplMSoftDAO" class="com.zw.dao.ToplMSoftDAO" parent="baseDao"></bean> <bean id="toplMSoftServiceImpl" class="com.zw.service.impl.ToplMSoftServiceImpl"> <property name="toplMSoftDAO" ref="toplMSoftDAO" /> </bean> [/code] 就不会报错 可以直接插入数据. 对Spring了解的不深 比较困惑 朋友们帮忙解答一下 谢谢

spring3+mybatis 注入空指针问题,请各位帮忙一下。

大家好,我刚学习三大框架,碰到一个空指针问题怎么都解决不了,快3天了,请帮忙下,谢谢了。 我测试所有的注入都是空指针 applicationContext.xml ``` <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jdbc=" http://www.springframework.org/schema/jdbc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd" default-autowire="byName" default-lazy-init="false"> <!-- 开启自动扫描并注册Bean定义支持 --> <!-- <context:component-scan base-package="cn.xhf"></context:component-scan> --> <!-- 采用注释的方式配置bean --> <!-- <context:annotation-config /> --> <!-- 配置datasource源 --> <context:property-placeholder location="classpath:mysql.properties" /> <!-- 使用mysql配置属性值 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${driver}" /> <property name="url" value="${url}" /> <property name="username" value="${username}" /> <property name="password" value="${password}" /> <property name="maxActive" value="${maxActive}"></property> <property name="maxIdle" value="${maxIdle}"></property> <property name="maxWait" value="${maxWait}"></property> <property name="defaultAutoCommit" value="${defaultAutoCommit}"></property> </bean> <!-- 配置sqlSessionFactory,同时制定数据源 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:Configuration.xml" /> </bean> <!-- 配置SqlSessionTemplate --> <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"> <constructor-arg index="0" ref="sqlSessionFactory" /> <constructor-arg index="1" value="BATCH" /> </bean> <!-- 配置dao --> <bean id="booksDao" class="cn.xhf.dao.impl.BooksDaoImpl"> <property name="sqlSession" ref="sqlSession"></property> </bean> <bean id="usersDao" class="cn.xhf.dao.impl.UsersDaoImpl"> <property name="sqlSession" ref="sqlSession"></property> </bean> <!-- 配置service --> <bean id="booksService" class="cn.xhf.service.impl.BooksServiceImpl" scope="prototype"> <property name="booksDao" ref="booksDao"></property> </bean> <bean id="usersService" class="cn.xhf.service.impl.UsersServiceImpl" scope="prototype"> <property name="usersDao" ref="usersDao"></property> </bean> <!-- 配置action --> <bean id="booksAction" class="cn.xhf.action.BooksAction" scope="prototype"> <property name="booksService" ref="booksService"></property> </bean> <bean id="usersAction" class="cn.xhf.action.UsersAction" scope="prototype"> <property name="usersService" ref="usersService"></property> </bean> <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!-- 通知 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="find*" read-only="true" /> <tx:method name="get*" read-only="true" /> <tx:method name="select*" read-only="true" /> </tx:attributes> </tx:advice> <!-- 切面配置 --> <!-- <aop:config> <aop:pointcut expression="execution(* cn.xhf.service.*.*(..))" id="method" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="method" /> </aop:config> --> </beans> ``` dao层 ``` package cn.xhf.dao.impl; import java.util.ArrayList; import java.util.List; import org.apache.ibatis.session.SqlSession; import org.springframework.beans.factory.annotation.Autowired; import cn.xhf.dao.BooksDao; import cn.xhf.pojo.Books; /** * */ public class BooksDaoImpl implements BooksDao { private SqlSession sqlSession; //就是这个空指针 ,其他bean也是空 @Override public int deleteBooksById(String bid) { return sqlSession.delete("books.deleteBooksById", bid); } @Override public int updataBooksById(String bid) { return sqlSession.update("books.updataBooksById", bid); } @Override public List<Books> findAll() { List<Books> booksList = new ArrayList<Books>(); booksList = sqlSession.selectList("books.findBooks"); return booksList; } @Override public List<Books> findBooksByKeyword(String bookName, String bookAuthor) { List<Books> bookList = new ArrayList<Books>(); // Books books = new Books(); // books.setBookName(bookName); // books.setBookAuthor(bookAuthor); // bookList = sqlSession.selectList("books.findBooks", books); return bookList; } @Override public int insertBooks(Books books) { return sqlSession.insert("books.insertBooks", books); } public SqlSession getSqlSession() { return sqlSession; } public void setSqlSession(SqlSession sqlSession) { this.sqlSession = sqlSession; } } ``` test方法 ``` package cn.xhf.pojo; import java.util.List; import cn.xhf.dao.BooksDao; import cn.xhf.dao.impl.BooksDaoImpl; public class TestBooks { public static void main(String[] args) { BooksDao booksDao = new BooksDaoImpl(); List<Books> list = booksDao.findAll(); System.out.println(list.size()); } } ``` 报错信息: Exception in thread "main" java.lang.NullPointerException at cn.xhf.dao.impl.BooksDaoImpl.findAll(BooksDaoImpl.java:32) at cn.xhf.pojo.TestBooks.main(TestBooks.java:11)

C/C++学习指南全套教程

C/C++学习的全套教程,从基本语法,基本原理,到界面开发、网络开发、Linux开发、安全算法,应用尽用。由毕业于清华大学的业内人士执课,为C/C++编程爱好者的教程。

定量遥感中文版 梁顺林著 范闻捷译

这是梁顺林的定量遥感的中文版,由范闻捷等翻译的,是电子版PDF,解决了大家看英文费时费事的问题,希望大家下载看看,一定会有帮助的

YOLOv3目标检测实战:训练自己的数据集

YOLOv3是一种基于深度学习的端到端实时目标检测方法,以速度快见长。本课程将手把手地教大家使用labelImg标注和使用YOLOv3训练自己的数据集。课程分为三个小项目:足球目标检测(单目标检测)、梅西目标检测(单目标检测)、足球和梅西同时目标检测(两目标检测)。 本课程的YOLOv3使用Darknet,在Ubuntu系统上做项目演示。包括:安装Darknet、给自己的数据集打标签、整理自己的数据集、修改配置文件、训练自己的数据集、测试训练出的网络模型、性能统计(mAP计算和画出PR曲线)和先验框聚类。 Darknet是使用C语言实现的轻型开源深度学习框架,依赖少,可移植性好,值得深入探究。 除本课程《YOLOv3目标检测实战:训练自己的数据集》外,本人推出了有关YOLOv3目标检测的系列课程,请持续关注该系列的其它课程视频,包括: 《YOLOv3目标检测实战:交通标志识别》 《YOLOv3目标检测:原理与源码解析》 《YOLOv3目标检测:网络模型改进方法》 敬请关注并选择学习!

sql语句 异常 Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your

在我们开发的工程中,有时候会报 [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ------ 这种异常 不用多想,肯定是我们的sql语句出现问题,下面...

浪潮集团 往年的软件类 笔试题 比较详细的哦

浪潮集团 往年的软件类 笔试题 比较详细的哦

2019 AI开发者大会

2019 AI开发者大会(AI ProCon 2019)是由中国IT社区CSDN主办的AI技术与产业年度盛会。多年经验淬炼,如今蓄势待发:2019年9月6-7日,大会将有近百位中美顶尖AI专家、知名企业代表以及千余名AI开发者齐聚北京,进行技术解读和产业论证。我们不空谈口号,只谈技术,诚挚邀请AI业内人士一起共铸人工智能新篇章!

I2c串口通信实现加速度传感器和FPGA的交流

此代码能实现加速度传感器与FPGA之间的交流,从而测出运动物体的加速度。

Python可以这样学(第一季:Python内功修炼)

董付国系列教材《Python程序设计基础》、《Python程序设计(第2版)》、《Python可以这样学》配套视频,讲解Python 3.5.x和3.6.x语法、内置对象用法、选择与循环以及函数设计与使用、lambda表达式用法、字符串与正则表达式应用、面向对象编程、文本文件与二进制文件操作、目录操作与系统运维、异常处理结构。

微信公众平台开发入门

本套课程的设计完全是为初学者量身打造,课程内容由浅入深,课程讲解通俗易懂,代码实现简洁清晰。通过本课程的学习,学员能够入门微信公众平台开发,能够胜任企业级的订阅号、服务号、企业号的应用开发工作。 通过本课程的学习,学员能够对微信公众平台有一个清晰的、系统性的认识。例如,公众号是什么,它有什么特点,它能做什么,怎么开发公众号。 其次,通过本课程的学习,学员能够掌握微信公众平台开发的方法、技术和应用实现。例如,开发者文档怎么看,开发环境怎么搭建,基本的消息交互如何实现,常用的方法技巧有哪些,真实应用怎么开发。

机器学习初学者必会的案例精讲

通过六个实际的编码项目,带领同学入门人工智能。这些项目涉及机器学习(回归,分类,聚类),深度学习(神经网络),底层数学算法,Weka数据挖掘,利用Git开源项目实战等。

eclipseme 1.7.9

eclipse 出了新的eclipseme插件,官方有下载,但特慢,我都下了大半天(可能自己网速差)。有急需要的朋友可以下哦。。。

Spring Boot -01- 快速入门篇(图文教程)

Spring Boot -01- 快速入门篇 今天开始不断整理 Spring Boot 2.0 版本学习笔记,大家可以在博客看到我的笔记,然后大家想看视频课程也可以到【慕课网】手机 app,去找【Spring Boot 2.0 深度实践】的课程,令人开心的是,课程完全免费! 什么是 Spring Boot? Spring Boot 是由 Pivotal 团队提供的全新框架。Spring Boot...

HoloLens2开发入门教程

本课程为HoloLens2开发入门教程,讲解部署开发环境,安装VS2019,Unity版本,Windows SDK,创建Unity项目,讲解如何使用MRTK,编辑器模拟手势交互,打包VS工程并编译部署应用到HoloLens上等。

最简单的倍频verilog程序(Quartus II)

一个工程文件 几段简单的代码 一个输入一个输出(50Mhz倍频到100Mhz)

计算机组成原理实验教程

西北工业大学计算机组成原理实验课唐都仪器实验帮助,同实验指导书。分为运算器,存储器,控制器,模型计算机,输入输出系统5个章节

4小时玩转微信小程序——基础入门与微信支付实战

这是一个门针对零基础学员学习微信小程序开发的视频教学课程。课程采用腾讯官方文档作为教程的唯一技术资料来源。杜绝网络上质量良莠不齐的资料给学员学习带来的障碍。 视频课程按照开发工具的下载、安装、使用、程序结构、视图层、逻辑层、微信小程序等几个部分组织课程,详细讲解整个小程序的开发过程

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

基于RSA通信密钥分发的加密通信

基于RSA通信密钥分发的加密通信,采用pycrypto中的RSA、AES模块实现

不同变质程度煤尘爆炸残留气体特征研究

为分析不同变质程度煤尘爆炸残留气体成分的特征规律,利用水平管道煤尘爆炸实验装置进行了贫瘦煤、肥煤、气煤、长焰煤4种不同变质程度的煤尘爆炸实验,研究了不同变质程度煤尘爆炸后气体残留物含量的差异,并对气体

设计模式(JAVA语言实现)--20种设计模式附带源码

课程亮点: 课程培训详细的笔记以及实例代码,让学员开始掌握设计模式知识点 课程内容: 工厂模式、桥接模式、组合模式、装饰器模式、外观模式、享元模式、原型模型、代理模式、单例模式、适配器模式 策略模式、模板方法模式、观察者模式、迭代器模式、责任链模式、命令模式、备忘录模式、状态模式、访问者模式 课程特色: 笔记设计模式,用笔记串连所有知识点,让学员从一点一滴积累,学习过程无压力 笔记标题采用关键字标识法,帮助学员更加容易记住知识点 笔记以超链接形式让知识点关联起来,形式知识体系 采用先概念后实例再应用方式,知识点深入浅出 提供授课内容笔记作为课后复习以及工作备查工具 部分图表(电脑PC端查看):

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

软件测试2小时入门

本课程内容系统、全面、简洁、通俗易懂,通过2个多小时的介绍,让大家对软件测试有个系统的理解和认识,具备基本的软件测试理论基础。 主要内容分为5个部分: 1 软件测试概述,了解测试是什么、测试的对象、原则、流程、方法、模型;&nbsp; 2.常用的黑盒测试用例设计方法及示例演示;&nbsp; 3 常用白盒测试用例设计方法及示例演示;&nbsp; 4.自动化测试优缺点、使用范围及示例‘;&nbsp; 5.测试经验谈。

几率大的Redis面试题(含答案)

本文的面试题如下: Redis 持久化机制 缓存雪崩、缓存穿透、缓存预热、缓存更新、缓存降级等问题 热点数据和冷数据是什么 Memcache与Redis的区别都有哪些? 单线程的redis为什么这么快 redis的数据类型,以及每种数据类型的使用场景,Redis 内部结构 redis的过期策略以及内存淘汰机制【~】 Redis 为什么是单线程的,优点 如何解决redis的并发竞争key问题 Red...

手把手实现Java图书管理系统(附源码)

【超实用课程内容】 本课程演示的是一套基于Java的SSM框架实现的图书管理系统,主要针对计算机相关专业的正在做毕设的学生与需要项目实战练习的java人群。详细介绍了图书管理系统的实现,包括:环境搭建、系统业务、技术实现、项目运行、功能演示、系统扩展等,以通俗易懂的方式,手把手的带你从零开始运行本套图书管理系统,该项目附带全部源码可作为毕设使用。 【课程如何观看?】 PC端:https://edu.csdn.net/course/detail/27513 移动端:CSDN 学院APP(注意不是CSDN APP哦) 本课程为录播课,课程2年有效观看时长,大家可以抓紧时间学习后一起讨论哦~ 【学员专享增值服务】 源码开放 课件、课程案例代码完全开放给你,你可以根据所学知识,自行修改、优化

jsp+servlet入门项目实例

jsp+servlet实现班级信息管理项目

winfrom中嵌套html,跟html的交互

winfrom中嵌套html,跟html的交互,源码就在里面一看就懂,很简单

Java面试题大全(2020版)

发现网上很多Java面试题都没有答案,所以花了很长时间搜集整理出来了这套Java面试题大全,希望对大家有帮助哈~ 本套Java面试题大全,全的不能再全,哈哈~ 一、Java 基础 1. JDK 和 JRE 有什么区别? JDK:Java Development Kit 的简称,java 开发工具包,提供了 java 的开发环境和运行环境。 JRE:Java Runtime Environ...

python实现数字水印添加与提取及鲁棒性测试(GUI,基于DCT,含测试图片)

由python写的GUI,可以实现数字水印的添加与提取,提取是根据添加系数的相关性,实现了盲提取。含有两种攻击测试方法(高斯低通滤波、高斯白噪声)。基于python2.7,watermark.py为主

Xshell6完美破解版,亲测可用

Xshell6破解版,亲测可用,分享给大家。直接解压即可使用

你连存活到JDK8中著名的Bug都不知道,我怎么敢给你加薪

CopyOnWriteArrayList.java和ArrayList.java,这2个类的构造函数,注释中有一句话 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 public ArrayList(Collection&lt;? ...

相关热词 c#框体中的退出函数 c# 按钮透明背景 c# idl 混编出错 c#在位置0处没有任何行 c# 循环给数组插入数据 c# 多线程死锁的例子 c# 钉钉读取员工排班 c# label 不显示 c#裁剪影像 c#工作进程更新ui
立即提问