Spring整合Jedis抛空异常

这是抛出的异常
严重: Servlet.service() for servlet TestServlet threw exception
java.lang.NullPointerException
at base.redis.RedisClientTemplateImpl.set(RedisClientTemplateImpl.java:49)
at test.web.TestServlet.doPost(TestServlet.java:27)
at test.web.TestServlet.doGet(TestServlet.java:18)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
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:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)

下面贴出我的代码:

图片说明

spring-redis.xml

ignore-unresolvable="true" />

<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
    <property name="maxTotal">
    <value>${redis.pool.maxActive}</value>
    </property>
    <property name="maxIdle">
     <value>${redis.pool.maxIdle}</value>
    </property>
    <property name="testOnBorrow" value="true"/>
    <property name="testOnReturn" value="true"/>
</bean>

 <bean id="shardedJedisPool" class="redis.clients.jedis.ShardedJedisPool"  scope="singleton">
    <constructor-arg index="0" ref="jedisPoolConfig" />
    <constructor-arg index="1">
        <list>
            <bean class="redis.clients.jedis.JedisShardInfo">
                <constructor-arg name="host" value="${redis.uri}" />
            </bean>
        </list>
    </constructor-arg>
</bean>
<bean id="redisDataSource" class="base.redis.RedisDataSourceImpl">
    <property name="shardedJedisPool"></property>
</bean>
<bean id="redisClientTemplate" class="base.redis.RedisClientTemplateImpl">
    <property name="redisDataSource"></property>
</bean>

RedisDataSourseImpl
private static final Logger log = Logger.getLogger(RedisDataSourceImpl.class);

private ShardedJedisPool shardedJedisPool;

public ShardedJedisPool getShardedJedisPool() {
return shardedJedisPool;
}
public void setShardedJedisPool(ShardedJedisPool shardedJedisPool) {
this.shardedJedisPool = shardedJedisPool;
}
/**

  • @return ShardedJedis
  • <获取redis客户端连接,执行命令> / public ShardedJedis getRedisClient() { System.out.println("执行getResource()前"); try { ShardedJedis shardedJedis = shardedJedisPool.getResource(); System.out.println("执行getResource()后"); return shardedJedis; } catch (Exception e) { log.error("获取redis客户端连接失败",e); } return null; } /*
  • @param shardedJedis
  • <将资源返还个pool>
    */
    public void returnResource(ShardedJedis shardedJedis) {

    shardedJedisPool.close();

}
/**

  • @param shardedJedis
  • <出现异常后,将资源返还给pool>
    */
    public void returnResource(ShardedJedis shardedJedis, boolean broken) {

    if(broken){
    shardedJedisPool.close();
    }else{
    shardedJedisPool.close();
    }

}

RedisClientTemplateImpl
private static final Logger log = Logger.getLogger(RedisClientTemplateImpl.class);

private RedisDataSource redisDataSource;

public RedisDataSource getRedisDataSource() {
return redisDataSource;
}
public void setRedisDataSource(RedisDataSource redisDataSource) {
this.redisDataSource = redisDataSource;
}
public void disconnect() {
System.out.println("disconnect()断开连接");
ShardedJedis shardedJedis = redisDataSource.getRedisClient();
shardedJedis.disconnect();
}
public String set(String key, String value) {
String result = null;
System.out.println("set方法");
ShardedJedis shardedJedis = redisDataSource.getRedisClient();
System.out.println("getRedisClient()执行后");
if (shardedJedis == null) {
return result;
}
boolean broken = false;
try {
result = shardedJedis.set(key, value);
} catch (Exception e) {
log.error(e.getMessage(), e);
broken = true;
} finally {
redisDataSource.returnResource(shardedJedis, broken);
}
return result;
}
TestServlet测试方法
RedisClientTemplateImpl redisClient = new RedisClientTemplateImpl();
String value = redisClient.set("yaya", "123156644");
System.out.println("获取到的值:"+value);
response.sendRedirect("index.jsp");

都有注入为什么抛出空异常,试了很多方法都不行,求大神帮忙解答一下,多分

5个回答

 <bean id="redisDataSource" class="base.redis.RedisDataSourceImpl">
    <property name="shardedJedisPool"></property>
</bean>
<bean id="redisClientTemplate" class="base.redis.RedisClientTemplateImpl">
    <property name="redisDataSource"></property>
</bean>

你配置都存在这些问题,你可以调试下嘛,问题定位了很快可以解决

weixin_38119445
uSeeWhat 问题解决了,jedisPoolConfig这个用构造器注入不能使用name,还有其他一些细节问题包括jedis版本啊,新研究的redis,谢谢指教啊
2 年多之前 回复



 <bean id="redisClientTemplate" class="base.redis.RedisClientTemplateImpl">
    <property name="redisDataSource" ref="redisDataSource"/>
</bean>
weixin_38119445
uSeeWhat 如果这里不容易看,可以加我微信1104929008我给你源码,帮我看一下
2 年多之前 回复
weixin_38119445
uSeeWhat 我照你的改了,加了ref还是一样啊
2 年多之前 回复

ShardedJedis shardedJedis = redisDataSource.getRedisClient();

从代码上来看抛空指针异常的只可能是这,同时看你配置文件


这redisDataSource并没有初始化,所以空指针很正常

有人帮忙解答一下吗?谢谢啦

这是我的redis.properties

redis.pool.maxActive=200
redis.pool.maxIdle=50
redis.pool.minIdle=10
redis.pool.maxWaitMillis=20000
redis.pool.maxWait=300
redis.uri = redis://:password@127.0.0.1:6379/0
redis.timeout=30000

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
request.setAttribute("list",list);抛空异常
request.setAttribute("list",list);抛空异常
spring整合redis案例(jedis)
spring4使用jedis整合redis,教程见博客地址:https://blog.csdn.net/zhou870498/article/details/79904475
redis3.0widows集群+spring整合jedis
redis3.0 widows集群 spring整合jedis redis搭建window集群代码和文档rubygems-2.5.1和rubyinstaller-2.2.3-x64软件下载
Spring整合Jedis分片 空指针异常
这是抛出的异常rn严重: Servlet.service() for servlet TestServlet threw exceptionrnjava.lang.NullPointerExceptionrn at base.redis.RedisClientTemplateImpl.set(RedisClientTemplateImpl.java:49)rn at test.web.TestServlet.doPost(TestServlet.java:27)rn at test.web.TestServlet.doGet(TestServlet.java:18)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)rn at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)rn at java.lang.Thread.run(Thread.java:619)rnrn下面贴出我的代码:rnrn[img=https://img-bbs.csdn.net/upload/201704/20/1492669199_614140.png][/img]rnrnspring-redis.xmlrnrn rn rn rn rn $redis.pool.maxActivern rn rn $redis.pool.maxIdlern rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrnRedisDataSourseImplrnprivate static final Logger log = Logger.getLogger(RedisDataSourceImpl.class);rn rn private ShardedJedisPool shardedJedisPool;rn rn public ShardedJedisPool getShardedJedisPool() rn return shardedJedisPool;rn rn public void setShardedJedisPool(ShardedJedisPool shardedJedisPool) rn this.shardedJedisPool = shardedJedisPool;rn rn /**rn * @return ShardedJedisrn * rn */rn public ShardedJedis getRedisClient() rn System.out.println("执行getResource()前");rn try rn ShardedJedis shardedJedis = shardedJedisPool.getResource();rn System.out.println("执行getResource()后");rn return shardedJedis;rn catch (Exception e) rn log.error("获取redis客户端连接失败",e);rn rn return null;rn rn /**rn * rn * @param shardedJedisrn * rn */rn public void returnResource(ShardedJedis shardedJedis) rnrn shardedJedisPool.close();rnrn rn /**rn * rn * @param shardedJedisrn * rn */ rn public void returnResource(ShardedJedis shardedJedis, boolean broken) rnrn if(broken)rn shardedJedisPool.close();rn elsern shardedJedisPool.close();rn rnrn rnrnRedisClientTemplateImplrnprivate static final Logger log = Logger.getLogger(RedisClientTemplateImpl.class);rn rn private RedisDataSource redisDataSource;rnrn public RedisDataSource getRedisDataSource() rn return redisDataSource;rn rn public void setRedisDataSource(RedisDataSource redisDataSource) rn this.redisDataSource = redisDataSource;rn rn public void disconnect() rn System.out.println("disconnect()断开连接");rn ShardedJedis shardedJedis = redisDataSource.getRedisClient();rn shardedJedis.disconnect();rn rn public String set(String key, String value) rn String result = null;rn System.out.println("set方法");rn ShardedJedis shardedJedis = redisDataSource.getRedisClient();rn System.out.println("getRedisClient()执行后");rn if (shardedJedis == null) rn return result;rn rn boolean broken = false;rn try rn result = shardedJedis.set(key, value);rn catch (Exception e) rn log.error(e.getMessage(), e);rn broken = true;rn finally rn redisDataSource.returnResource(shardedJedis, broken);rn rn return result;rn rnTestServlet测试方法rnRedisClientTemplateImpl redisClient = new RedisClientTemplateImpl();rn String value = redisClient.set("yaya", "123156644");rn System.out.println("获取到的值:"+value);rn response.sendRedirect("index.jsp");rnrn都有注入为什么抛出空异常,试了很多方法都不行,求大神帮忙解答一下,多分
Redis客户端之Spring整合Jedis
1.下载相关jar包,并引入工程: jedis-2.4.2.jar commons-pool2-2.0.jar 2.将以下XML配置引入spring &amp;lt;bean id=&quot;shardedJedisPool&quot; class=&quot;redis.clients.jedis.ShardedJedisPool&quot;&amp;gt; &amp;lt;constructor-arg index=&quot;0&quot; ...
newstyles项目实战(二十)jedis与Spring整合
Spring和Jedis结合配置:Jedis连接池的配置:&amp;lt;!-- 连接池配置 --&amp;gt; &amp;lt;bean id=&quot;jedisPoolConfig&quot; class=&quot;redis.clients.jedis.JedisPoolConfig&quot;&amp;gt; &amp;lt;!-- 最大连接数 --&amp;gt; &amp;lt;property name=&quot;maxTotal&quot; value=&quot;30&
Spring整合redis(jedis)实现Session共享
今天来记录一下自己在整合框架过程中所遇到的问题:    在用redis实现session共享时,项目启动报 No bean named 'springSessionRepositoryFilter' is defined 异常    在调用缓存工具类的时候显示注入的JedisPool为Null...
spring整合redis和jedis客户端问题
在spring整合redis和jedis客户端中,jedis的版本会对我们的整合产生影响。 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisTemplate'  这里的spring是4.2.4 ,原先使用的jedis是2.8.0.从而有了上面的报错问题;首先...
spring整合hibernate异常
严重: Context initialization failedrnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [D:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\team\WEB-INF\classes\spring\applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/log4j/Levelrn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:883)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)rn at java.security.AccessController.doPrivileged(Native Method)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)rn at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)rn at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)rn at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)rn at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764)rn at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216)rn at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)rn at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)rn at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)rn at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)rn at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)rn at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)rn at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)rn at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)rn at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)rn at org.apache.catalina.core.StandardService.start(StandardService.java:448)rn at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)rn at org.apache.catalina.startup.Catalina.start(Catalina.java:552)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)rn at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)rn
spring整合hibernate出现的异常!
在整合spring与hibernate的过程中,使用的mysql数据库,始终出现org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YES))这个异常提示,可是,在另外一个项目中,同样整合了spring和hibernate,同样使用了mysql数据库,用户名和密码也是一样的,却没有出现这个异常提示!实在已经找不出什么解决
JAVA抛空指针的代码!
PrintWriter out = null;rnout.println("SUCCESS");rnout.close();rnrn---------------------------------------------rn以上代码指定会抛空指针异常,哪里抛出的?为什么抛出?求解啊!!!!!
记录一个 jedis 异常备忘
at redis.clients.jedis.Connection.flush(Connection.java:333) redis也是在本机, 使用的ip为 127.0.0.1   使用jedis连接一直都是正常 但今天却报错:at redis.clients.jedis.Connection.flush(Connection.java:333)   用手机做热点, 连上网络,  i...
jedis 连接redis超时异常
1、redis 部署环境 centos7.0 2、通过jedis 源码调试 出现错误,如下 Exception in thread “main” redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out
Jedis连接Redis异常的问题
jedis连接Redis异常: Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect at redis.clients.jedis.Connection.connect(Connection.java:154) at redis.clients.jedis.BinaryClient.
急急急,看看为什么会抛空异常呢?
代码:rnimport java.io.IOException;rnimport java.io.PrintWriter;rnrnimport javax.servlet.ServletException;rnimport javax.servlet.http.HttpServlet;rnimport javax.servlet.http.HttpServletRequest;rnimport javax.servlet.http.HttpServletResponse;rnimport java.sql.*;rnrnpublic class InitServlet extends HttpServlet rnprivate String driver="";rnprivate String URL="";rnprivate String username="";rnprivate String password="";rnpublic void destroy() rnsuper.destroy(); rnrnrn// Just puts "destroy" string in logrn// Put your code herernrnpublic void doGet(HttpServletRequest request, HttpServletResponse response)rnthrows ServletException, IOException rnrnresponse.setContentType("text/html;charset=gbk");rnPrintWriter out = response.getWriter();rnConnection con = this.getConnection();rntryrnStatement stmt=con.createStatement();rnResultSet rs=stmt.executeQuery("select * from user");rnwhile(rs.next())rnout.print(rs.getString("u_id"));rnout.println();rnout.print(rs.getString("u_name"));rnout.print(rs.getString("u_password"));rnrnrncatch(SQLException e)rne.printStackTrace();rnrnrnrnpublic void doPost(HttpServletRequest request, HttpServletResponse response)rnthrows ServletException, IOException rndoGet(request,response);rnrnrnpublic void init() throws ServletException rndriver=getInitParameter("driver");rnURL=getInitParameter("URL");rnusername=getInitParameter("username");rnpassword=getInitParameter("password");rnrnpublic Connection getConnection()rnConnection con=null;rntryrnClass.forName(driver);rncon = DriverManager.getConnection(URL,username,password);rnSystem.out.print("2");rnrncatch(Exception e)rnrnrnreturn con;rnrnrnrnrn错误信息:rn严重: Servlet.service() for servlet InitServlet threw exceptionrnjava.lang.NullPointerExceptionrnat ch02.InitServlet.doGet(InitServlet.java:31)rnat javax.servlet.http.HttpServlet.service(HttpServlet.java:617)rnat javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rnat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rnat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rnat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rnat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)rnat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)rnat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rnat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rnat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)rnat org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)rnat org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)rnat org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)rnat java.lang.Thread.run(Unknown Source)
Spring整合junit出现的版本异常
Spring整合junit出现的console和junit界面无提示的异常 /** * @author:xhz * @time: 2018年8月15日 */ package com.xhz.springAOP; import org.aspectj.lang.ProceedingJoinPoint; /** * @author xhz * @scription:增强UserS...
hessian与Spring整合 莫名奇妙的异常
spring和hessian整合异常问题 以前也做过这个整合 这次做个新项目换了spring版本和hessian版本,开始出现如下两个奇妙的错误。配置没有任何变化。 com.caucho.hessian.io.HessianProtocolException com.caucho.hessian.client.HessianConnectionException:   后面看了下sp...
spring整合mybatis的异常,求解决。。。
运行tomcat是,总是报错:查找了很多资料,没找到原因:rnrn2012-08-28 14:33:49,531 >> ERROR >> main >> >> [org.springframework.web.context.ContextLoader] : Context initialization failedrnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'class path resource [SqlMapConfig.xml]'; nested exception is java.lang.RuntimeException: Error parsing Mapper XML. Cause: java.lang.NullPointerExceptionrn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:591)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)rn at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)rn at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)rn at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)rn at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)rn at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)rn at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)rn at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)rn at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)rn at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)rn at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)rn at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)rn at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)rn at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)rn at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)rn at org.apache.catalina.core.StandardService.start(StandardService.java:525)rn at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)rn at org.apache.catalina.startup.Catalina.start(Catalina.java:595)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:585)rn at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)rn at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)rnCaused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: 'class path resource [SqlMapConfig.xml]'; nested exception is java.lang.RuntimeException: Error parsing Mapper XML. Cause: java.lang.NullPointerExceptionrn at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:412)rn at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:295)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)rn ... 36 morernCaused by: java.lang.RuntimeException: Error parsing Mapper XML. Cause: java.lang.NullPointerExceptionrn at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:113)rn at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:88)rn at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:410)rn ... 39 morernCaused by: java.lang.NullPointerExceptionrn at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:104)rn ... 41 morernrn rnrn rnrnSpring中的配置:rnrn rnrnrn rn rn rnrn rnrn rnrnSqlMapConfig.xml中的配置:rnrnrn rn rn rn rn rnrn rnrn rnrnroleMapper.xml配置:rnrnrnrnrnrnrnrnrnrnrnrnrnrn rn rn SELECT * FROM OM_ROLE_Trn rn rn
mybatis和spring整合出现的sql异常
Caused by: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)出现错误的原因:1.用户名或者密码错误2.如果用户名和密码都是正确的,需要看下面两个配置文件对应的地方是否相同:applicationContext.xml中的部分:&amp;lt;!-- 数据库连接池 --&amp;gt...
Java通过Jedis连接Redis异常,错误记录
紧接上一篇文章,Centos7下Redis安装教程 我用Jedis连接Redis时报错,代码和错误如下图 解决方案: 在redis.conf这个配置文件中,找到bind和protected-mode这两个属性,将其修改。 默认: 修改后: 在vmware中创建centos7虚拟机并安装Redis后,如果以redis.conf配置文件运行的话,只能本机(仅仅是...
jedis,spring-redis-data 整合使用,版本问题异常
jedis,spring-redis-data 整合使用,版本不匹配的时候经常火爆一些异常,例如 1: java.lang.NoClassDefFoundError: org/springframework/data/geo/Metric 2:java.lang.NoSuchMethodError: redis.clients.jedis.JedisCluster.set([B[B)Lja
Jedis 源码阅读一 —— Jedis
这是jedis 源码目录,我们接下来选择性阅读重要的接口以及实现。└─redis └─clients ├─jedis │ │ BinaryClient.java │ │ BinaryJedis.java │ │ BinaryJedisCluster.java │ │ BinaryJedisPubS
Jedis常见的三个异常及解决方式
用Linux虚拟机Centos6.5搭建个redis,在用Jedis连接时遇到了各种问题 1.redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect 报错信息如下: 出现这个异常 是在防火墙关闭或者指定端口开启正常 而re...
jedis源码 (学习jedis)
jedis源码 (学习jedis必备,附带测试用例)
spring整合jedis没有maxActive和maxWait对应setter方法报错
下午闲来无事自己动手集成spring和redis,参考网上的博客配置好了Spring配置文件,做单元测试启动时结果一直报错,“maxWait”和“maxActive”属性值非法,接着排查到底是哪里的问题 <bean id="JedisConnectionFactory" class="org.springframework.data.redis
调用Spring整合Hibernate下的saveOrUpdateAll()方法时报异常
今天在一个项目中使用了Spring整合Hibernate下的saveOrUpdateAll(Collection collection)方法,但是程序在运行的过程中有时会抛出一个java.util.ConcurrentModificationException的异常,我对为什么会出现的这样的异常感到非常奇怪。rn首先,我传给这个方法的参数是一个List的集合,其中是需要存储到数据库的对象,基本上可以确信没有其它的线程在同时处理这个集合。rn其次,我在程序的外层通过一个DAO对象的方法调用了这个方法,调用之后对作为传入的List参数对象进行了clear()操作,例如:rn[code=Java]DataDAO.save(list);rnlist.clear()[/code]rn在save()方法中调用了[code=Java]getHibernateTemplate().saveOrUpdateAll(list)[/code]rn如果说改变了list集合,那也应该是执行了数据库操作之后才改变的呀!rnrn如果不是这个原因的话,那会是什么原因导致这个异常抛出的呢?希望大家能知道一下,感激不尽!谢谢!
cxf与spring整合抛了一个异常,求帮助!
cxf与spring整合不知道是不是jar冲突问题 spring2.5 和cxf2.5rn[code=java]rnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cxf' defined in class path resource [META-INF/cxf/cxf.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.apache.cxf.bus.spring.SpringBus]: Constructor threw exception; nested exception is java.lang.IncompatibleClassChangeError: Implementing classrn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)rn at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384)rn at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)rn at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)rn at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)rn at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)rn at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)rn at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)rn at org.apache.catalina.core.StandardService.start(StandardService.java:525)rn at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)rn at org.apache.catalina.startup.Catalina.start(Catalina.java:595)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)rn at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)rnCaused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.apache.cxf.bus.spring.SpringBus]: Constructor threw exception; nested exception is java.lang.IncompatibleClassChangeError: Implementing classrn at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:162)rn at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:76)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:990)rn ... 28 morernCaused by: java.lang.IncompatibleClassChangeError: Implementing classrn at java.lang.ClassLoader.defineClass1(Native Method)rn at java.lang.ClassLoader.defineClass(ClassLoader.java:621)rn at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)rn at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2854)rn at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)rn at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)rn at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)rn at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)rn at java.lang.ClassLoader.defineClass1(Native Method)rn at java.lang.ClassLoader.defineClass(ClassLoader.java:621)rn at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)rn at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2854)rn at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)rn at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)rn at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)rn at org.apache.cxf.bus.extension.Extension.getClassObject(Extension.java:149)rn at org.apache.cxf.bus.extension.ExtensionManagerImpl.activateAllByType(ExtensionManagerImpl.java:137)rn at org.apache.cxf.bus.extension.ExtensionManagerBus.(ExtensionManagerBus.java:131)rn at org.apache.cxf.bus.extension.ExtensionManagerBus.(ExtensionManagerBus.java:143)rn at org.apache.cxf.bus.spring.SpringBus.(SpringBus.java:46)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)rn at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)rn at java.lang.reflect.Constructor.newInstance(Constructor.java:513)rn at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)rn ... 30 morern[/code]
关于spring整合hibernate 懒加载异常解决方案
最近在做spring整合hibernate的项目,把hibernate的事物交给spring管理,但是在懒加载的时候出现的在懒加载时候session的时候这个时候已经关闭了,导致懒加载异常,这个时候本着有事找百度的态度,在百度上搜索全都是一样的,在web.xml或者在spring MVC中配置懒加载信息,而且在百度上的都是一样的,后来看了一下官方文档,在hibernate配置内加一句话就行了,真心
Redis + Spring整合遇到的Spring初始化bean异常
转自:http://zhaobing315.iteye.com/blog/2082189 项目中需要用到缓存,经过比较后,选择了redis,客户端使用jedis连接,也使用到了spring提供的spring-data-redis。配置正确后启动tomcat,发现如下异常: Caused by: org.springframework.beans.factory.BeanCreationExc...
Spring整合Hibernate时出现的sessionFactory配置异常
我用JUnit做单元测试,手动启动Spring容器时一切正常,但从Tomcat加载Spring的applicationContext.xml文件时却报了如下的错误,请大家帮我看看,谢谢rn我的Spring是配置在web.xml中的rnrn org.springframework.web.context.ContextLoaderListenerrn rn严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerrnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V
Jedis源码解析——Jedis和BinaryJedis
1、基本信息先来看看他们的类定义:public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommands, AdvancedJedisCommands, ScriptingCommands, BasicCommands, ClusterCommands, SentinelCommands {
Jedis使用+jedis再封装
一 、Redis初始化(RedisStart.class) package com.ciri.cache; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; /**  * Created b
spring整合系列教程——spring整合mybatis
一、spring整合mybatis 1.首先您需要建立一个父pom工程,来管理jar包的版本 【项目结构图】 请自动忽略被遮挡的内容 【spring-root/pom.xml】 &amp;lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-insta...
spring整合
Spring整合Struts2 、 使用Result 、 使用拦截器 、 ValueStack.docx 适合初学者进行阅读
Spring整合
一个springMVC+Mybatis+spring 整合版的小demo
Jedis简介,Jedis 的 HelloWorld,设置redis连接密码,Jedis 连接池实例,和jedis常用方法
Jedis简介 实际开发中,我们需要用Redis的连接工具连接Redis然后操作Redis。 redis都提供了对应的客户端https://redis.io/clients 官方推荐的是Jedis 托管地址:https://github.com/xetorthio/jedis 那jedis就是集成了redis的一些命令操作,封装了redis的java客户端。提供了连接池管理。一般不直...
REDIS学习(5)jedis 和 jedis连接池
目前情况是 srping boot中测试代码 mvn的包为: org.springframework.boot spring-boot-starter-redis
jedis通过JedisSentinelPool获取jedis操作redis
jedis通过JedisSentinelPool获取jedis操作redis,通过配置sentienl,获取sentinel连接池,通过sentinel,获取jedis信息
jedis工具类
package com.unicoin.utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig;...
Jedis学习
http://snowolf.iteye.com/blog/1633196 [url=http://snowolf.iteye.com/blog/1630697]征服 Redis[/url] 征服 Redis + Jedis 征服 Redis + Jedis + Spring (一)—— 配置&amp;常规操作(GET SET DEL) 征服 Redis + Jedis + Spring (二...
相关热词 c# 线程结束时执行 c# kb mb 图片 c# 替换第几位字符 c#项目决定成败 c# 与matlab c# xml缩进 c#传感器基础 c#操作wps c# md5使用方法 c# 引用父窗口的组件