关于Hibernate和spring整合访问mysql数据库,在action层出现空指针错误。

琢磨好几天,百度了许多相关知识 ,对初学者的我还是没有能解决,希望能得到大神们的帮助,在此先谢过!
废话不说,先说问题,我想整合hibernate和spring,没有用Struts,
然后在如下配置bean

    <bean id="testAction" class="com.sven.action.TestAction">
        <property name="memberService">
            <ref bean="memberService"/>
        </property>
    </bean> 


    <bean id="memberService" class="com.sven.service.impl.SwMemberServiceImpl">
        <property name="memberDao">
            <ref bean="memberDao"/>
        </property>
    </bean> 

    <bean id="memberDao" class="com.sven.dao.impl.SwMemberDaoImpl">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>

我自己也不知道对不对,然后目录结构如下图
目录结构

经过测试,在service层可以成功注入dao。

然后对应的action类如下

 package com.sven.action;


import org.junit.Test;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

import com.sven.entity.SwMember;
import com.sven.service.SwMemberService;

public class TestAction{
    /**
     * 注入业务层
     */ 
    private SwMemberService memberService;

    public void setMemberService(SwMemberService memberService) {
        this.memberService = memberService;
    }


    public void testAction() {      
        SwMember member = this.memberService.findMemberById(19);
        System.out.println(member.getUsername() + " "+member.getName());
    }

    @Test
    public void test() {

        XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));

        SwMemberService dao = (SwMemberService) factory.getBean("memberService");

        SwMember member = dao.findMemberById(19);

        System.out.println(member.getUsername() + " "+member.getName());
    }

}

经过测试 ,里面的test方法,不通过注入的形式,直接获取bean可以成功,得到数据(id=19这个存在数据),然后通过一般的注入,使用testAction方法,就报错,报错如下图:
图片说明

这问题出在哪呢?

望大神指教。

2个回答

你只运行这一个方法时,,貌似木有加载spring的配置文件是不是,,,,,

Spring的配置文件都木有加载,,那就没后话了,,

先加载spring配置文件,这是前提,,

你这个没理解好,spring文件中配置的东西还需要用getbean来获取,也就是你 的 id="testAction"这个bean 配置到文件中了,,
但是测试框架运行时会,不会加载你这个bean,,,所以还需要自己获取一下,,,

问题比较多,,感觉你对spring单元测试没弄好,,慢慢来,,有问题还可以追问

把test()的中的前两行复制到testAction()中再试试(this.memberService改为dao,方法上加上@Test注解),如果你的测试方法很多,你可以把spring容器初始化的代码单独搞一个init()方法嘛。正如楼上说的,你对单元测试理解不够,每一个测试方法都要初始化spring容器的,不然你怎么getBean啊。

jingguo_vip
jingguo_vip 回复SvenBarnett: good lucky! 共同学习嘛
2 年多之前 回复
SvenBarnett
SvenBarnett 回复jingguo_vip: 谢大哥,是您说的问题,目前已经解决。
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Struts和Spring整合后访问Action注入失败
如题,刚刚接触SSH,不知道是哪配置出问题了, 蛋疼的是单元测试中用ClassPathXmlApplicationContext读取spring配置文件却通过了- - Struts2配置: <struts> <!-- 设置浏览器是否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭 --> <constant name="struts.serve.static.browserCache" value="false" /> <!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false(生产环境下使用),开发阶段最好打开 --> <constant name="struts.configuration.xml.reload" value="true" /> <!-- 开发模式下使用,这样可以打印出更详细的错误信息 --> <constant name="struts.devMode" value="true" /> <!-- <constant name="struts.action.extension" value="do,app" /> --> <constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory" /> <!-- Configuration for the default package. --> <package name="default" extends="struts-default,json-default"> <action name="*_*" method="{2}" class="org.crush.mlms.action.{1}Action"> <result type="json"> <param name="success">responseJson</param> </result> </action> </package> </struts> Spring配置: <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="url" value="jdbc:mysql://localhost:3306/mlms"></property> <property name="username" value="root"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop> </props> </property> <property name="mappingResources"> <list> <value>org/crush/mlms/domain/Test.hbm.xml</value> </list> </property> </bean> <bean id="testAction" class="org.crush.mlms.action.TestAction"> <property name="testService"> <ref bean="TestService" /> </property> <property name="testDao"> <ref bean="testDAO" /> </property> <property name="factory"> <ref bean="sessionFactory" /> </property> </bean> <bean id="testDAO" class="org.crush.mlms.domain.TestDAO"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <bean id="TestService" class="org.crush.mlms.service.TestService"> <property name="testDao"> <ref bean="testDAO" /> </property> </bean> web.xml配置: <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>MLMS</display-name> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:Bean.xml</param-value> </context-param> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file> index.html </welcome-file> </welcome-file-list> </web-app>
struts2+Hibernate+spring整合问题(异常
异常信息: exception Unable to instantiate Action, loginAction, defined for 'loginAction' in namespace '/'loginAction com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:318) com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:399) com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:198) org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61) org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39) com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:475) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) root cause java.lang.ClassNotFoundException: loginAction org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680) org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526) com.opensymphony.xwork2.util.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:157) com.opensymphony.xwork2.ObjectFactory.getClassInstance(ObjectFactory.java:107) com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:223) com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:143) com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:150) com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:120) com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:299) com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:399) com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:198) org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61) org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39) com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:475) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) 导入的jar文件: [img]http://dl.iteye.com/upload/picture/pic/90617/97d45138-0021-3cbe-a1a1-167ab1e0cc8c.jpg[/img] [img]http://dl.iteye.com/upload/picture/pic/90615/be54d974-693d-3ac1-b742-f9902c0c6969.jpg[/img] web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app> 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:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql://localhost:3306/test"></property> <property name="username" value="root"></property> <property name="password" value=""></property> <property name="maxActive" value="100"></property> <property name="maxIdle" value="30"></property> <property name="maxWait" value="500"></property> <property name="defaultAutoCommit" value="true"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> <property name="mappingResources"> <list> <value>com/gufengxiachen/s2sh/bean/User.hbm.xml</value> </list> </property> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <constructor-arg> <ref local="sessionFactory"/> </constructor-arg> </bean> <!-- 把DAO注入给Session工厂 --> <bean id="userDao" class="com.gufengxiachen.s2sh.daoimpl.UserDAOImpl" > <property name="sessionFactory"> <ref bean="sessionFactory"/> </property> </bean> <!-- 把Service注入给DAO --> <bean id="userService" class="com.gufengxiachen.s2sh.serviceimpl.UserServiceImpl"> <property name="userDao" ref="userDao"> </property> </bean> <!-- 把Action注入给Service --> <bean id="loginAction" class="com.gufengxiachen.s2sh.action.LoginAction"> <property name="userService" ref="userService"> </property> </bean> </beans> struts.xml: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="s2sh" extends="struts-default" namespace="/"> <action name="loginAction" class="loginAction"> <result name="success">/result.jsp</result> <result name="input">/index.jsp</result> </action> </package> </struts> hibernate映射文件: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="com.gufengxiachen.s2sh.bean" table="user"> <id name="id" column="id" type="int"> <generator class="increment"></generator> </id> <property name="username" column="username" type="string"></property> <property name="password" type="string"></property> </class> </hibernate-mapping>
ssh整合,找不到action,如果不给action加class属性就能访问
http://pan.baidu.com/s/1kVPk56J 这是项目 使用:需要先在hibernate.cfg.xml中配置一下用户名和密码还有数据库路径 需要mysql数据库,随便能连一个数据库就可以,不然会报错,只有初始化用到了spring,hibernate action里面直接返回了success 两个action一个可以访问一个找不到路径,但是类的映射是对的,用ctrl有下划线 ![图片说明](https://img-ask.csdn.net/upload/201610/19/1476869362_828609.png) 图上的配置文件在config源文件夹,struts/struts-staff.xml struts.xml主配置文件中导入了这个配置文件
struts2 spring hibernate3 连mysql问题
<p>我用struts2+spring+hibernate3连数据库mysql,只要访问8次action,ie就停顿了,就一直在加载,控制台也没反应。只能重启服务器tomcat,重启之后也只能访问8次。mysql中最大连接数配置max_connections=1024 <br>spring-common.xml</p> <pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" 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.0.xsd"&gt; &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt; &lt;property name="driverClassName"&gt; &lt;value&gt;com.mysql.jdbc.Driver&lt;/value&gt; &lt;/property&gt; &lt;property name="url"&gt; &lt;value&gt;jdbc:mysql://localhost:3306/facebs?useunicode=true&amp;amp;characterEncoding=utf-8&lt;/value&gt; &lt;/property&gt; &lt;property name="username"&gt; &lt;value&gt;root&lt;/value&gt; &lt;/property&gt; &lt;property name="password"&gt; &lt;value&gt;344&lt;/value&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" &gt; &lt;property name="mappingResources"&gt; &lt;list&gt; &lt;value&gt;com/idbao/common/hibernate/AccountState.hbm.xml&lt;/value&gt; &lt;!--........省略一部分&lt;value&gt;--&gt; &lt;/list&gt; &lt;/property&gt; &lt;property name="hibernateProperties"&gt; &lt;props&gt; &lt;prop key="hibernate.dialect"&gt; org.hibernate.dialect.MySQLDialect &lt;/prop&gt; &lt;prop key="hibernate.show_sql"&gt; true &lt;/prop&gt; &lt;prop key="hibernate.c3p0.min_size"&gt;5&lt;/prop&gt; &lt;prop key="hibernate.c3p0.max_size"&gt;20&lt;/prop&gt; &lt;prop key="hibernate.c3p0.timeout"&gt;1800&lt;/prop&gt; &lt;prop key="hibernate.c3p0.max_statements"&gt;50&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;property name="dataSource"&gt; &lt;ref bean="dataSource"/&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory"/&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory"/&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="smsUtil" class="com.idbao.common.util.SmsUtil"&gt; &lt;/bean&gt; &lt;/beans&gt; </pre> <p> </p> <p> spring-service.xml</p> <pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" 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.0.xsd"&gt; &lt;bean id="memberInfoServiceTarget" class="com.idbao.member.service.impl.MemberInfoServiceImpl"&gt; &lt;property name="memberInfoDao"&gt; &lt;ref bean="memberInfoDao"/&gt; &lt;/property&gt; &lt;property name="smsUtil"&gt; &lt;ref bean="smsUtil"/&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="memberInfoService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" lazy-init="true"&gt; &lt;property name="transactionManager"&gt; &lt;ref bean="transactionManager" /&gt; &lt;/property&gt; &lt;property name="transactionAttributes"&gt; &lt;props&gt; &lt;prop key="*"&gt;PROPAGATION_REQUIRED, -MemberInfoException&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;property name="target"&gt; &lt;ref bean="memberInfoServiceTarget"/&gt; &lt;/property&gt; &lt;/bean&gt; &lt;!--.....省略一部分bean--&gt; &lt;/beans&gt; </pre> <p>  <br>daoImp.java</p> <pre name="code" class="java">public class daoImpl implements dao { private HibernateTemplate hibernateTemplate; public void setHibernateTemplate(HibernateTemplate hibernateTemplate){ this.hibernateTemplate=hibernateTemplate; } public CateringBaseParameter findCatering(Integer id) throws DataAccessException { List list=hibernateTemplate.find("from CateringBaseParameter where id=?",id); if(list.size()!=0) return (CateringBaseParameter) list.get(0); return null; } }</pre> <p> </p> <p> </p> <p>请指教有什么错误,不胜感激!</p>
SSH框架Hibernate基于Spring自动生成的DAO怎样使用
applicantContext.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:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd" xmlns:tx="http://www.springframework.org/schema/tx"> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> <bean id="UserDAO" class="org.dao.UserDAO"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> </beans> ``` Hibernate.cfg.xml ``` <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <!-- Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration> <session-factory> <property name="dialect"> org.hibernate.dialect.MySQLDialect </property> <property name="connection.url"> jdbc:mysql://localhost:3306/ </property> <property name="connection.username">root</property> <property name="connection.password">root</property> <property name="connection.driver_class"> com.mysql.jdbc.Driver </property> <property name="myeclipse.connection.profile">mysql</property> <property name="hibernate.hbm2ddl.auto">update</property> <property name="hibernate.show_sql">true</property> <property name="hibernate.format_sql">true</property> <property name="cache.use_query_cache">true</property> <property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property> <property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property> <property name="current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</property> <mapping resource="org/vo/User.hbm.xml" /> </session-factory> </hibernate-configuration> ``` UserDAO类 ``` public class UserDAO { private static final Logger log = LoggerFactory.getLogger(UserDAO.class); // property constants public static final String UNAME = "uname"; public static final String PASSWORD = "password"; private SessionFactory sessionFactory; public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } private Session getCurrentSession() { return sessionFactory.getCurrentSession(); } protected void initDao() { // do nothing } public void save(User transientInstance) { log.debug("saving User instance"); try { getCurrentSession().save(transientInstance); log.debug("save successful"); } catch (RuntimeException re) { log.error("save failed", re); throw re; } } public void delete(User persistentInstance) { log.debug("deleting User instance"); try { getCurrentSession().delete(persistentInstance); log.debug("delete successful"); } catch (RuntimeException re) { log.error("delete failed", re); throw re; } } public User findById(java.lang.Integer id) { log.debug("getting User instance with id: " + id); try { User instance = (User) getCurrentSession().get("org.vo.User", id); return instance; } catch (RuntimeException re) { log.error("get failed", re); throw re; } } public List<?> findByExample(User instance) { log.debug("finding User instance by example"); try { List<?> results = getCurrentSession().createCriteria("org.vo.User") .add(Example.create(instance)).list(); log.debug("find by example successful, result size: " + results.size()); return results; } catch (RuntimeException re) { log.error("find by example failed", re); throw re; } } public List<?> findByProperty(String propertyName, Object value) { log.debug("finding User instance with property: " + propertyName + ", value: " + value); try { String queryString = "from User as model where model." + propertyName + "= ?"; Query queryObject = getCurrentSession().createQuery(queryString); queryObject.setParameter(0, value); return queryObject.list(); } catch (RuntimeException re) { log.error("find by property name failed", re); throw re; } } public List<?> findByUname(Object uname) { return findByProperty(UNAME, uname); } public List<?> findByPassword(Object password) { return findByProperty(PASSWORD, password); } public List<?> findAll() { log.debug("finding all User instances"); try { String queryString = "from User"; Query queryObject = getCurrentSession().createQuery(queryString); return queryObject.list(); } catch (RuntimeException re) { log.error("find all failed", re); throw re; } } public User merge(User detachedInstance) { log.debug("merging User instance"); try { User result = (User) getCurrentSession().merge(detachedInstance); log.debug("merge successful"); return result; } catch (RuntimeException re) { log.error("merge failed", re); throw re; } } public void attachDirty(User instance) { log.debug("attaching dirty User instance"); try { getCurrentSession().saveOrUpdate(instance); log.debug("attach successful"); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } } public void attachClean(User instance) { log.debug("attaching clean User instance"); try { getCurrentSession().buildLockRequest(LockOptions.NONE).lock( instance); log.debug("attach successful"); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } } public static UserDAO getFromApplicationContext(ApplicationContext ctx) { return (UserDAO) ctx.getBean("UserDAO"); } } ``` HibernateSessionFactory类 ``` public class HibernateSessionFactory { /** * Location of hibernate.cfg.xml file. * Location should be on the classpath as Hibernate uses * #resourceAsStream style lookup for its configuration file. * The default classpath location of the hibernate config file is * in the default package. Use #setConfigFile() to update * the location of the configuration file for the current session. */ private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>(); private static org.hibernate.SessionFactory sessionFactory; private static Configuration configuration = new Configuration(); private static ServiceRegistry serviceRegistry; static { try { configuration.configure(); serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); } catch (Exception e) { System.err.println("%%%% Error Creating SessionFactory %%%%"); e.printStackTrace(); } } private HibernateSessionFactory() { } /** * Returns the ThreadLocal Session instance. Lazy initialize * the <code>SessionFactory</code> if needed. * * @return Session * @throws HibernateException */ public static Session getSession() throws HibernateException { Session session = (Session) threadLocal.get(); if (session == null || !session.isOpen()) { if (sessionFactory == null) { rebuildSessionFactory(); } session = (sessionFactory != null) ? sessionFactory.openSession() : null; threadLocal.set(session); } return session; } /** * Rebuild hibernate session factory * */ public static void rebuildSessionFactory() { try { configuration.configure(); serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); } catch (Exception e) { System.err.println("%%%% Error Creating SessionFactory %%%%"); e.printStackTrace(); } } /** * Close the single hibernate session instance. * * @throws HibernateException */ public static void closeSession() throws HibernateException { Session session = (Session) threadLocal.get(); threadLocal.set(null); if (session != null) { session.close(); } } /** * return session factory * */ public static org.hibernate.SessionFactory getSessionFactory() { return sessionFactory; } /** * return hibernate configuration * */ public static Configuration getConfiguration() { return configuration; } } ``` 测试类 ``` package org.action; import org.dao.UserDAO; import org.vo.User; public class Test { public static void main(String[] args) { // TODO Auto-generated method stub // Session session = HibernateSessionFactory.getSession(); // session.beginTransaction(); // 插入数据 // session.save(new User("大傻", "123")); // 通过id查询数据 // User user = (User) session.load(User.class, 1); // System.out.println(user.getPassword()); // 通过id查找并删除数据 // User user = (User) session.get(User.class, 8); // session.delete(user); // 通过id查找并修改数据 // User user = (User) session.load(User.class, 9); // user.setPassword("999999"); // session.saveOrUpdate(user); // UserDAO userDAO = new UserDAO(); User user = new User("Jone", "111111"); userDAO.save(user); // session.getTransaction().commit(); // session.close(); } } ``` * 错误提示 ``` SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Exception in thread "main" java.lang.NullPointerException at org.dao.UserDAO.getCurrentSession(UserDAO.java:41) at org.dao.UserDAO.save(UserDAO.java:51) at org.action.Test.main(Test.java:40) ``` 第一行指向 ``` UserDAO的private Session getCurrentSession() { return sessionFactory.getCurrentSession(); } ``` 第二行错误指向 ``` public void save(User transientInstance) { log.debug("saving User instance"); try { # getCurrentSession().save(transientInstance); log.debug("save successful"); } catch (RuntimeException re) { log.error("save failed", re); throw re; } } ```
spring boot 集成activiti如何能在启动时不配置数据库参数
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>leave</artifactId> <version>0.0.1-SNAPSHOT</version> <name>leave</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring-boot-starter-basic</artifactId> <version>6.0.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web-services</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> ------上面是spring boot 的pom.xml 在application.properties配置好数据库参数就可以正常运行。我的想法是在程序启动的时候不连接数据库,在程序运行的过程中按需连接到数据库,但我删除了数据可参数的时候就报错了!!!信息如下: Description: Cannot determine embedded database driver class for database type NONE Action: If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active). 在网上找到的解决方案是添加注解(分别如下尝试都出错): 1.------------------------- @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class}) @SpringBootApplication 2.--------------------------------------- @SpringBootApplication(exclude={DataSourceAutoConfiguration.class}) 3.------------------------------------ @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class,DataSourceTransactionManagerAutoConfiguration.class,HibernateJpaAutoConfiguration.class}) 错误信息如下: Description: Parameter 0 of method springProcessEngineConfiguration in org.activiti.spring.boot.JpaProcessEngineAutoConfiguration$JpaConfiguration required a bean of type 'javax.sql.DataSource' that could not be found. - Bean method 'dataSource' not loaded because @ConditionalOnProperty (spring.datasource.jndi-name) did not find property 'jndi-name' - Bean method 'dataSource' not loaded because @ConditionalOnBean (types: org.springframework.boot.jta.XADataSourceWrapper; SearchStrategy: all) did not find any beans Action: Consider revisiting the conditions above or defining a bean of type 'javax.sql.DataSource' in your configuration
struts2+hibernate+spring+proxool性能问题
项目已经跑了2个多月了,今天突然出现不能访问的问题。 第一开始是访问一直刷不出页面,但是tomcat控制台却一下一下的在执行,(很慢的执行,很久才输出一条hibernate的语句) 之后将所有的应用重启了一次, 依然访问不了网站。 一直让他持续连接就会给我报错。 [code="java"] 2009-09-24 11:47:12 [org.logicalcobwebs.proxool.BESTVDB]-[WARN] #0008 was active for 1939871 milliseconds and has been removed automaticaly. The Thread responsible was named 'http-8080-Processor45', and the last SQL it performed is 'select iptvaction0_.action_id as action1_, iptvaction0_.uid as uid11_, iptvaction0_.username as username11_, iptvaction0_.con as con11_, iptvaction0_.cat as cat11_, iptvaction0_.friend_id as friend6_11_, iptvaction0_.friendname as friendname11_, iptvaction0_.code as code11_, iptvaction0_.state_id as state9_11_, iptvaction0_.remark as remark11_, iptvaction0_.datetime as datetime11_, iptvaction0_.allowed as allowed11_, iptvaction0_.visable as visable11_, iptvaction0_.action_place as action14_11_ from iptv_action iptvaction0_ where iptvaction0_.uid in (select iptvmyfrie1_.friendid from iptv_myfriends iptvmyfrie1_ where iptvmyfrie1_.uid=723) order by iptvaction0_.datetime desc limit 3; '. 2009-09-24 11:47:12 [org.hibernate.transaction.JDBCTransaction]-[ERROR] Could not toggle autocommit com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) at com.mysql.jdbc.Util.getInstance(Util.java:381) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:985) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927) at com.mysql.jdbc.ConnectionImpl.checkClosed(ConnectionImpl.java:1113) at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:4790) at sun.reflect.GeneratedMethodAccessor126.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.logicalcobwebs.proxool.WrappedConnection.invoke(WrappedConnection.java:162) at org.logicalcobwebs.proxool.WrappedConnection.intercept(WrappedConnection.java:87) at com.mysql.jdbc.Connection$$EnhancerByProxool$$6a89ac94.setAutoCommit(<generated>) at org.hibernate.transaction.JDBCTransaction.toggleAutoCommit(JDBCTransaction.java:174) at org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JDBCTransaction.java:122) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:95) at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:578) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:662) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:632) [/code] [code="java"] javax.servlet.ServletException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin failed: org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515) org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419) org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:99) org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75) root cause org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin failed: org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:541) org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:350) root cause org.hibernate.TransactionException: JDBC begin failed: org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:58) org.hibernate.transaction.JDBCTransactionFactory.beginTransaction(JDBCTransactionFactory.java:24) org.hibernate.jdbc.JDBCContext.beginTransaction(JDBCContext.java:271) org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1079) org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:510) root cause java.sql.SQLException: Couldn't perform the operation getAutoCommit: You can't perform any operations on this connection. It has been automatically closed by Proxool for some reason (see logs). org.logicalcobwebs.proxool.WrappedConnection.invoke(WrappedConnection.java:207) org.logicalcobwebs.proxool.WrappedConnection.intercept(WrappedConnection.java:87) com.mysql.jdbc.ConnectionProperties$$EnhancerByProxool$$9313bf3c.getAutoCommit(<generated>) org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:49) org.hibernate.transaction.JDBCTransactionFactory.beginTransaction(JDBCTransactionFactory.java:24) org.hibernate.jdbc.JDBCContext.beginTransaction(JDBCContext.java:271) [/code] 异常信息大概如上所示。 找不到头绪。 不知道该如何下手去优化?还是? 我该如何做? 这是我的第一个项目。还希望各位前辈给出指点!谢谢!
服务器 mysql数据库异常
查看服务器的log日志的时候,发现服务器中经常报一些如下的错误: [code="java"] 2009-02-06 08:22:20,588 INFO [cn.legend.myznt.util.SystemExceptionHandler] - 出现异常 org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin failed: Caused by: org.hibernate.TransactionException: JDBC begin failed: at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:68) at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1290) at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:510) at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:350) at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:262) 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.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:629) at cn.qdrk.strive.dao.hibernate.UserDaoHibernate$$EnhancerByCGLIB$$10afb0ec.queryAccount(<generated>) at cn.qdrk.strive.struts.action.LoginAction.execute(LoginAction.java:44) at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110) 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:190) at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304) at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190) 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:710) 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:75) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75) 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:175) 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:263) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Unknown Source) Caused by: com.mysql.jdbc.CommunicationsException: Communications link failure Last packet sent to the server was 120 ms ago. at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1070) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2985) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2871) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3414) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536) at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:4874) at org.apache.tomcat.dbcp.dbcp.DelegatingConnection.setAutoCommit(DelegatingConnection.java:331) at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.setAutoCommit(PoolingDataSource.java:317) at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:63) ... 41 more Caused by: java.net.SocketException: Software caused connection abort: recv failed at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(Unknown Source) at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113) at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:160) at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188) at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2428) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2882) ... 50 more 2009-02-06 08:22:20,588 INFO [cn.legend.myznt.util.SystemExceptionHandler] - 出现异常 org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin failed: Caused by: org.hibernate.TransactionException: JDBC begin failed: at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:68) at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1290) at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:510) at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:350) at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:262) 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.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:629) at cn.qdrk.strive.dao.hibernate.UserDaoHibernate$$EnhancerByCGLIB$$10afb0ec.queryAccount(<generated>) at cn.qdrk.strive.struts.action.LoginAction.execute(LoginAction.java:44) at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110) 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:190) at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304) at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190) 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:710) 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:75) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75) 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:175) 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:263) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Unknown Source) Caused by: com.mysql.jdbc.CommunicationsException: Communications link failure Last packet sent to the server was 120 ms ago. at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1070) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2985) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2871) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3414) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536) at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:4874) at org.apache.tomcat.dbcp.dbcp.DelegatingConnection.setAutoCommit(DelegatingConnection.java:331) at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.setAutoCommit(PoolingDataSource.java:317) at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:63) ... 41 more Caused by: java.net.SocketException: Software caused connection abort: recv failed at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(Unknown Source) at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113) at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:160) at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188) at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2428) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2882) ... 50 more [/code] 感觉数据库好像有时没连上,但是过一会好像就好了,我的tomcat配置的链接池如下: [code="java"] <Resource name = "jdbc/sqlds" auth = "Container" type = "javax.sql.DataSource" maxIdle = "30" maxWait = "10000" maxActive = "10" username = "root" password = "123456" driverClassName = "com.mysql.jdbc.Driver" url = "jdbc:mysql://localhost:3306/test?zeroDateTimeBehavior=convertToNull" /> <Resource name = "jdbc/sqlds" auth = "Container" type = "javax.sql.DataSource" maxIdle = "30" maxWait = "10000" maxActive = "10" username = "root" password = "123456" driverClassName = "com.mysql.jdbc.Driver" url = "jdbc:mysql://localhost:3306/test?zeroDateTimeBehavior=convertToNull" /> [/code] applicationContext.xml中配置如下: [code="java"] <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="java:comp/env/jdbc/sqlds"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="java:comp/env/jdbc/sqlds"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> [/code] 是由于MySQL对于超过8小时的连接就会强行关闭,而数据库连接池并不知道,仍然持有失效的连接,当从连接池中取出并使用这种连接的时候就会出错 ,这个该怎么改呢?万分感谢!
spring+hibernate3查询速度
系统 struts + spring + hibernate3,数据库mysql5.0 机器2G内存,cpu双核(具体的没见) 表结构: [code="sql"]received_message(//接受短信表 id int not null autoincrement, action varchar(255), .... game_code_int bigint,//代表游戏 party_code_int bigint,//代表渠道 status_int bigint,//表示计费成功状态 rece_date datetime,//接受时间 money float default 0//短信价格 ) party(//渠道商的表 id int not null auto_increment, .... party_code_int bigint,//和上面的party_code_int一样 ) game(//游戏所对应 id int not null auto_increment, .... game_code_int bigint,//和上面的game_code_int对应 )[/code] 现在received_message表里面有30多万条数据 查询变的很慢,有的时候要等1分钟,甚至更长 BOSS要求在查询时候必须是即时信息,所以我自己也没有办法去缓存received_message表里面的数据 查询的时候经常出现select count(party_code_int),sum(money) from received_message where party_code_int=? 或者select count(game_code_int),sum(money) from received_message where game_code_int=? and rece_date > ? 这样类似的查询语句 具体还需要什么办法,请帮忙解答下,我现在很郁闷,小弟是java刚刚入门!
关于spring、struts、hibernate三大框架整合的疑惑!
刚刚开始接触spring、struts、hibernate三大框架,在网上还有朋友那里获得了一些帮助,自己写了一个小的登录模块,但是不知道是否真正的实现了三大框架整合,希望各位前辈高手多多指点 <br /> <br />现在把我的几个配置文件展示如下: <br />web.xml <br /><pre name="code" class="xml"> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/classes/applicationContext.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;servlet&gt; &lt;servlet-name&gt;action&lt;/servlet-name&gt; &lt;servlet-class&gt;org.apache.struts.action.ActionServlet&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;config&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/struts-config.xml&lt;/param-value&gt; &lt;/init-param&gt; &lt;init-param&gt; &lt;param-name&gt;debug&lt;/param-name&gt; &lt;param-value&gt;3&lt;/param-value&gt; &lt;/init-param&gt; &lt;init-param&gt; &lt;param-name&gt;detail&lt;/param-name&gt; &lt;param-value&gt;3&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;0&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;action&lt;/servlet-name&gt; &lt;url-pattern&gt;*.do&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;welcome-file-list&gt; &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt; &lt;/welcome-file-list&gt; &lt;/web-app&gt; </pre> <br /> <br />spring: <br /><pre name="code" class="xml"> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" 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.0.xsd"&gt; &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt; &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"&gt; &lt;/property&gt; &lt;property name="url" value="jdbc:mysql://127.0.0.1:3306/test"&gt;&lt;/property&gt; &lt;property name="username" value="root"&gt;&lt;/property&gt; &lt;property name="password" value="123456"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt; &lt;property name="dataSource"&gt; &lt;ref bean="dataSource" /&gt; &lt;/property&gt; &lt;property name="hibernateProperties"&gt; &lt;props&gt; &lt;prop key="hibernate.dialect"&gt; org.hibernate.dialect.MySQLDialect &lt;/prop&gt; &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;property name="mappingResources"&gt; &lt;list&gt; &lt;value&gt;com/xh/pojo/User.hbm.xml&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="User" class="com.xh.pojo.User"&gt;&lt;/bean&gt; &lt;bean id="UserDAO" class="com.xh.dao.UserDAO"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="CheckLogin" class="com.xh.service.impl.CheckLoginImpl"&gt; &lt;property name="user"&gt; &lt;ref bean="User"/&gt; &lt;/property&gt; &lt;property name="userDAO"&gt; &lt;ref bean="UserDAO"/&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean name="/login" class="com.yourcompany.struts.action.LoginAction"&gt; &lt;property name="checkLogin"&gt; &lt;ref bean="CheckLogin"/&gt; &lt;/property&gt; &lt;/bean&gt; &lt;/beans&gt; </pre> <br /> <br /> <br />struts: <br /><pre name="code" class="xml"> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"&gt; &lt;struts-config&gt; &lt;form-beans &gt; &lt;form-bean name="loginForm" type="com.yourcompany.struts.form.LoginForm" /&gt; &lt;/form-beans&gt; &lt;global-exceptions /&gt; &lt;global-forwards /&gt; &lt;action-mappings &gt; &lt;action attribute="loginForm" input="main.jsp" name="loginForm" path="/login" scope="request" type="org.springframework.web.struts.DelegatingActionProxy" &gt; &lt;forward name="success" path="/main.jsp"&gt;&lt;/forward&gt; &lt;forward name="failure" path="/index.jsp"&gt;&lt;/forward&gt; &lt;/action&gt; &lt;/action-mappings&gt; &lt;message-resources parameter="com.yourcompany.struts.ApplicationResources" /&gt; &lt;plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"&gt; &lt;set-property property="contextConfigLocation" value="/WEB-INF/classes/applicationContext.xml"/&gt; &lt;/plug-in&gt; &lt;/struts-config&gt; </pre> <br /> <br />
struts+ spring+hibernate 无法添加Action 求帮助
application.xml文件 <br /> <br />XML code <br /><pre name="code" class="xml"> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"&gt; &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"&gt;&lt;/property&gt; &lt;property name="url" value="jdbc:mysql://localhost:3306/ects"&gt;&lt;/property&gt; &lt;property name="username" value="root"&gt;&lt;/property&gt; &lt;property name="password" value="1234"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;bean id="sessionFatory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt; &lt;property name="dataSource" ref="dataSource"&gt;&lt;/property&gt; &lt;property name="mappingResources"&gt; &lt;list&gt; &lt;value&gt;cn/com/ambow/ects/entity/xml/User.hbm.xml&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;property name="hibernateProperties"&gt; &lt;props&gt; &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.format_sql"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt; &lt;property name="sessionFactory" ref="sessionFatory"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"&gt; &lt;property name="sessionFactory" ref="sessionFatory"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;bean id="userdao" class="cn.com.ambow.ects.dao.impl.UserDaoImpl"&gt; &lt;property name="hibernateTemplate" ref="hibernateTemplate"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;bean id="Dyuser" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"&gt; &lt;property name="target" ref="userdao"&gt;&lt;/property&gt; &lt;property name="transactionManager" ref="transactionManager"&gt;&lt;/property&gt; &lt;property name="transactionAttributes"&gt; &lt;props&gt; &lt;prop key="*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean name="/struts/action/login" class="cn.com.ambow.ects.struts.action.UserAction" &gt; &lt;property name="userDaoImpl" ref="Dyuser"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;/beans&gt; </pre> <br /> <br /> <br /> <br />struts-config.xml文件 <br /> <br />XML code <br /><pre name="code" class="xml"> &lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd"&gt; &lt;struts-config&gt; &lt;action-mappings&gt; &lt;!-- 用户登录--&gt; &lt;action path="/struts/action/login" type="cn.com.ambow.ects.struts.action.UserAction" parameter="login"&gt; &lt;forward name="success" path="/flower/index.jsp"&gt;&lt;/forward&gt; &lt;forward name="error" path="/flower/myaccount.jsp"&gt;&lt;/forward&gt; &lt;/action&gt; &lt;/action-mappings&gt; &lt;controller&gt; &lt;set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor" /&gt; &lt;/controller&gt; &lt;plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"&gt; &lt;set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" /&gt; &lt;/plug-in&gt; &lt;/struts-config&gt; </pre> <br /> <br /> <br />web.xml文件 <br /> <br />XML code <br /><pre name="code" class="xml"> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt; &lt;servlet&gt; &lt;servlet-name&gt;action&lt;/servlet-name&gt; &lt;servlet-class&gt;org.apache.struts.action.ActionServlet&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;config&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/struts-config.xml&lt;/param-value&gt; &lt;/init-param&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;action&lt;/servlet-name&gt; &lt;url-pattern&gt;*.do&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;welcome-file-list&gt; &lt;welcome-file&gt;/flower/index.jsp&lt;/welcome-file&gt; &lt;/welcome-file-list&gt; &lt;/web-app&gt; </pre> <br /> <br /> <br />错误信息 <br />严重: action: null <br />org.springframework.beans.factory.BeanCreationException: Error creating bean with name '/struts/action/login' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy0] to required type [cn.com.ambow.ects.dao.impl.UserDaoImpl] for property 'userDaoImpl'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy0] to required type [cn.com.ambow.ects.dao.impl.UserDaoImpl] for property 'userDaoImpl': no matching editors or conversion strategy found <br />at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:478) <br />at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) <br />at java.security.AccessController.doPrivileged(Native Method) <br />at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) <br />at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) <br />at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:217) <br />at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) <br />at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) <br />at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) <br />at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429) <br />at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729) <br />at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381) <br />at org.springframework.web.struts.ContextLoaderPlugIn.createWebApplicationContext(ContextLoaderPlugIn.java:354) <br />at org.springframework.web.struts.ContextLoaderPlugIn.initWebApplicationContext(ContextLoaderPlugIn.java:295) <br />at org.springframework.web.struts.ContextLoaderPlugIn.init(ContextLoaderPlugIn.java:225) <br />at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:869) <br />at org.apache.struts.action.ActionServlet.init(ActionServlet.java:336) <br />at javax.servlet.GenericServlet.init(GenericServlet.java:212) <br />at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172) <br />at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:808) <br />at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129) <br />at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) <br />at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) <br />at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) <br />at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) <br />at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) <br />at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) <br />at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) <br />at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) <br />at java.lang.Thread.run(Thread.java:619) <br />Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy0] to required type [cn.com.ambow.ects.dao.impl.UserDaoImpl] for property 'userDaoImpl'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy0] to required type [cn.com.ambow.ects.dao.impl.UserDaoImpl] for property 'userDaoImpl': no matching editors or conversion strategy found <br />at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:391) <br />at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1287) <br />at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1248) <br />at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1008) <br />at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470) <br />... 29 more <br />Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy0] to required type [cn.com.ambow.ects.dao.impl.UserDaoImpl] for property 'userDaoImpl': no matching editors or conversion strategy found <br />at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:238) <br />at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138) <br />at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386) <br />... 33 more <br />2011-12-19 10:01:59 org.apache.catalina.core.ApplicationContext log <br />信息: Marking servlet action as unavailable <br />2011-12-19 10:01:59 org.apache.catalina.core.StandardWrapperValve invoke <br />严重: Allocate exception for servlet action<pre name="code" class="java"></pre><pre name="code" class="java"></pre><br/><strong>问题补充</strong><br/>谁能帮我解决一下啊
Struts2+hibernate+spring事务配置没起作用
struts.xml <br /><pre name="code" class="java"> &lt;action name="index" class="indexAction"&gt; &lt;result name="success"&gt;/top5w.jsp&lt;/result&gt; &lt;/action&gt; </pre> <br /> <br />applicationContext.xml <br /><pre name="code" class="java"> &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt; &lt;property name="driverClassName"&gt;&lt;value&gt;com.mysql.jdbc.Driver&lt;/value&gt;&lt;/property&gt; &lt;property name="url"&gt;&lt;value&gt;jdbc:mysql://localhost:3306/te&lt;/value&gt;&lt;/property&gt; &lt;property name="username"&gt;&lt;value&gt;root&lt;/value&gt;&lt;/property&gt; &lt;property name="password"&gt;&lt;value&gt;root&lt;/value&gt;&lt;/property&gt; &lt;property name="maxActive"&gt;&lt;value&gt;100&lt;/value&gt;&lt;/property&gt; &lt;property name="maxIdle"&gt;&lt;value&gt;20&lt;/value&gt;&lt;/property&gt; &lt;property name="maxWait"&gt;&lt;value&gt;100&lt;/value&gt;&lt;/property&gt; &lt;/bean&gt; &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;property name="hibernateProperties"&gt; &lt;props&gt; &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt; &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;property name="mappingLocations"&gt; &lt;list&gt; &lt;value&gt;classpath:com/zhang/tao/model/*.hbm.xml&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt; &lt;property name="sessionFactory" ref="sessionFactory" /&gt; &lt;/bean&gt; &lt;bean id="indexAction" class="com.zhang.struts.action.IndexAction" scope="prototype"&gt; &lt;property name="wordService" ref="kwordService" /&gt; &lt;/bean&gt; &lt;bean id="kwordService" class="com.zhang.struts.service.KwordService"&gt; &lt;property name="sessionFactory" ref="sessionFactory" /&gt; &lt;/bean&gt; </pre> <br /> <br />KwordService.java <br /><pre name="code" class="java"> private SessionFactory sessionFactory; public SessionFactory getSessionFactory() { return sessionFactory; } public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } public List&lt;?&gt; getResult(String hql,int currPage){ // Session session = sessionFactory.openSession(); Session session = sessionFactory.getCurrentSession(); Transaction tr = session.beginTransaction(); Query query = session.createQuery(hql); query.setFirstResult(50*currPage); query.setMaxResults(50); List&lt;?&gt; list = query.list(); tr.commit(); // session.close(); return list; } </pre> <br /> <br />IndexAction.java <br /><pre name="code" class="java"> private KwordService wordService; public String toIndex(){ HttpServletRequest request = ServletActionContext.getRequest(); List&lt;?&gt; list = null; String hql = "from com.zhang.tao.model.Kword"; list = wordService.getResult(hql,1); </pre> <br /> <br />如果在KwordService.java里用sessionFactory.openSession()就OK,但用getCurrentSession()就报错 <br />如果在kwordservice类里使用session = sessionFactory.openSession();就OK,如果使用getCurrentSession()就报错 <br />org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here <br />
求解决No Hibernate Session bound to thread
ssh项目在运行时控制台没有出错,但是页面出现 HTTP Status 500 - No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here怎么解决??? ![图片说明](https://img-ask.csdn.net/upload/201503/18/1426660994_104397.jpg) 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: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-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql://localhost:3306/hk"></property> <property name="username" value="root"></property> <property name="password" value="123"></property> <property name="maxActive" value="100"></property> <property name="maxIdle" value="30"></property> <property name="maxWait" value="500"></property> <property name="defaultAutoCommit" value="true"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop> </props> </property> <property name="mappingResources"> <list> <value>vo/News.hbm.xml</value></list> </property></bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED" /><!-- 只有一save、delete、update开头的方法才能执行增删改操作 --> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="*" propagation="SUPPORTS" read-only="true" /><!-- 其他方法为只读方法 --> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="interceptorPointCuts" expression="execution(* news.serviceImpl..*.*(..))" /> <!-- 对应实现类接口的包的位置 --> <aop:advisor advice-ref="txAdvice" pointcut-ref="interceptorPointCuts" /> </aop:config> <!-- 业务层Service --> <bean id="news_service" class="service.impl.NewsServiceImpl"> <property name="sessionFactory"> <ref bean="sessionFactory"></ref> </property> </bean> <!-- 控制层Action --> <bean id="news_action" class="action.NewsAction"> <property name="news_services"> <ref bean="news_service" /> </property> </bean> </beans> 初学ssh的菜鸟,请各位大神帮忙解答一下!!谢谢!
spring 加载hibernate配置文件时候tomcat无法启动
我在做一个web项目的入门小例子,可是tomcat无法启动 。 服务器为 :tomcat 5 开发环境为: spring+hibernate+struts spring的配置文件如下: 红色的地方是出问题的地方。把红色的地方注释掉才能启动。 ?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" 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 = "dataSource" class = "org.apache.commons.dbcp.BasicDataSource" destroy-method = "close" > <property name = "driverClassName" value = "com.mysql.jdbc.Driver"/> <property name = "url" value = "jdbc:mysql://localhost:3306/advertisement"/> <property name = "username" value = "root" /> <property name = "password" value ="850524li"/> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name ="dataSource" ref = "dataSource" /> [color=red] <property name = "mappingResources"> <list> <value>/Login.hbm.xml</value> </list> </property> [/color] <!-- <property name ="hibernateProperties"> <props> <prop key = "hibernate.dialect">org.hibernate.dialect.MySQLDBDialect</prop> </props> </property> --> </bean> <!-- <bean id="LoginDAO" class="com.advertisement.login.dao.LoginDAO"> <property name="sessionFactory"> <ref bean="sessionFactory"></ref> </property> </bean> <bean id = "facadeManager" class = "com.advertisement.login.manager.FacadeManager"> <property name = "loginDAO" ref = "LoginDAO"/> </bean> --> <bean name = "/loginAction" class = "com.advertisement.login.action.LoginAction"> <!-- <property name = "facadeManager" ref = "facadeManager"/>--> </bean> </beans> struts的配置文件如下 。 从struts中启动spring <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"> <struts-config> <data-sources /> <form-beans > <form-bean name="loginForm" type="com.advertisement.login.form.LoginForm" /> </form-beans> <global-exceptions /> <global-forwards /> <action-mappings > <action path="/loginAction" type= "com.advertisement.login.action.LoginAction" name = "loginForm" validate="false" input = "/login1.jsp"> <forward name="success" path="/success.jsp" /> <forward name = "error" path = "/error.jsp"/> </action> </action-mappings> <controller processorClass = "org.springframework.web.struts.DelegatingRequestProcessor"/> <plug-in className = "org.springframework.web.struts.ContextLoaderPlugIn" > <set-property property = "contextConfigLocation" value = "/WEB-INF/applicationContext.xml"/> </plug-in> </struts-config> hibernate的映射文件如下:: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse Persistence Tools --> <hibernate-mapping> <class name="com.advertisement.login.dao.Login" table="login" catalog="advertisement"> <id name="keyid" type="java.lang.Long"> <column name="keyid" /> <generator class="assigned" /> </id> <property name="operatorNo" type="java.lang.String"> <column name="operatorNo" length="50" not-null="true" /> </property> <property name="operatorName" type="java.lang.String"> <column name="operatorName" length="50" not-null="true" /> </property> <property name="operatorType" type="java.lang.String"> <column name="operatorType" length="50" not-null="true" /> </property> <property name="telephone" type="java.lang.String"> <column name="telephone" length="50" not-null="true" /> </property> </class> </hibernate-mapping>
spring 连接数据库的问题
<p><span style=""><strong>用的spring+hibernate,那位达人能帮忙解决下,感激不尽.<br />web.xml里:</strong></span><br />....<br />&lt;context-param&gt;<br />  &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;<br />  &lt;param-value&gt;<br />   /WEB-INF/applicationContext.xml<br />  &lt;/param-value&gt;<br /> &lt;/context-param&gt;<br /> &lt;servlet&gt;<br />    &lt;servlet-name&gt;context&lt;/servlet-name&gt;<br />    &lt;servlet-class&gt;org.springframework.web.context.ContextLoaderServlet&lt;/servlet-class&gt;<br />    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;<br />&lt;/servlet&gt;<br /><span style="">....</span></p> <p><span style=""><strong>applicationContext.xml里:</strong></span><br />....<br />&lt;bean id="dataSource" &lt;br=""&gt;  class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;<br />  &lt;property name="driverClassName" &lt;br=""&gt;   value="com.mysql.jdbc.Driver"&gt;<br />  &lt;/property&gt;<br />  &lt;property name="url" &lt;br=""&gt;   value="jdbc:mysql://localhost:3306/test"&gt;<br />  &lt;/property&gt;<br />  &lt;property name="username" value="root"&gt;&lt;/property&gt;<br />  &lt;property name="password" value="root"&gt;&lt;/property&gt;<br /> &lt;/bean&gt;<br /> &lt;bean id="sessionFactory" &lt;br=""&gt;  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;<br />  &lt;property name="dataSource"&gt;<br />   &lt;ref bean="dataSource"&gt;<br />  &lt;/property&gt;<br />  &lt;property name="hibernateProperties"&gt;<br />   &lt;props&gt;<br />    &lt;prop key="hibernate.dialect"&gt;<br />     org.hibernate.dialect.MySQLDialect<br />    &lt;/prop&gt;<br />   &lt;/props&gt;<br />  &lt;/property&gt;<br />  &lt;property name="mappingResources"&gt;<br />   &lt;list&gt;<br />    &lt;value&gt;com/test/vo/User.hbm.xml&lt;/value&gt;<br />  &lt;/property&gt;</p> <p>&lt;/bean&gt;</p> <p>&lt;bean id="transactionManager" &lt;br=""&gt;   class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;<br />       &lt;property name="sessionFactory"&gt;<br />           &lt;ref local="sessionFactory"&gt;<br />       &lt;/property&gt;<br />  &lt;/bean&gt;<br />  &lt;bean id="userDAOProxy" &lt;br=""&gt;   class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"&gt;<br />     &lt;property name="transactionManager"&gt;<br />         &lt;ref bean="transactionManager"&gt;<br />     &lt;/property&gt;<br />     &lt;property name="target"&gt;<br />         &lt;ref local="userDAO"&gt;<br />     &lt;/property&gt;<br />     &lt;property name="transactionAttributes"&gt;<br />         &lt;props&gt;<br />            &lt;prop key="save*"&gt;PROPAGATION_REQUIRED &lt;/prop&gt; <br />            &lt;prop key="update*"&gt;PROPAGATION_REQUIRED &lt;/prop&gt; <br />            &lt;prop key="delete*"&gt;PROPAGATION_REQUIRED &lt;/prop&gt; <br />            &lt;prop key="find*"&gt;PROPAGATION_REQUIRED,readOnly &lt;/prop&gt;<br />         &lt;/props&gt;<br />     &lt;/property&gt;<br />   &lt;/bean&gt;</p> <p> &lt;bean id="userDAO" class="com.test.dao.Impl.UserDAOImpl"&gt;<br />  &lt;property name="sessionFactory"&gt;<br />   &lt;ref bean="sessionFactory"&gt;<br />  &lt;/property&gt;<br /> &lt;/bean&gt;<br />....</p> <p> </p> <p><span style=""><strong>DAO里:</strong></span></p> <p><strong><span style="">...</span></strong></p> <p><br />public class UserDAOImpl extends HibernateDaoSupport implements UserDAO{<br /> private static final Log log = LogFactory.getLog(UserDAOImpl.class);<br /> private String hql = "from user u where u.name = ?";<br /> private boolean bo= false;<br /> <br /> protected void initDao() {<br />  // do nothing<br /> }</p> <p> public boolean save(User user) {<br />  try {<br />   this.getHibernateTemplate().save(user);//<span style=""><strong>执行到这里出错,User对象里的name和passwd不是空的</strong></span>.<br />   this.getHibernateTemplate().flush();//<span style=""><strong>getHibernateTemplate()调用的各种操作都出现这样的错误.</strong></span><br />   bo = true;<br />  } catch (RuntimeException re) {<br />   throw re;<br />  }<br />  return bo;<br /> }</p> <p>}</p> <p>.......</p> <p><span style=""><strong>出现的错误提示如下:</strong></span></p> <p>2008-8-22 13:18:34 org.apache.catalina.core.StandardWrapperValve invoke<br />严重: Servlet.service() for servlet regedit threw exception<br />java.lang.NullPointerException<br /> at com.test.dao.Impl.UserDAOImpl.save(UserDAOImpl.java:41)<br /> at com.test.service.Impl.RegeditImpl.save(RegeditImpl.java:27)<br /> at com.test.action.RegeditController.doPost(RegeditController.java:32)<br /> at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)<br /> at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)<br /> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)<br /> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)<br /> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)<br /> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)<br /> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)<br /> at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)<br /> at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)<br /> at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)<br /> at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)<br /> at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)<br /> at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)<br /> at java.lang.Thread.run(Thread.java:674)</p> <p> </p><br /><strong>问题补充:</strong><br />我把spring 配置文件里的标签随便删几个,让不对应,或把dataSource改了,竟然还是提示这样的错误!!! <br />在web.xml里使用listener,启动tomcat时就出错. <br />郁闷了啊!<br /><strong>问题补充:</strong><br />怎么测试spring hibernate 连接数据库了?
spring配置问题,求帮助
[color=#FF0000]applicationContext.xml:[/color] <?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:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd" xmlns:tx="http://www.springframework.org/schema/tx"> <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/mytest" /> <property name="username" value="root" /> <property name="password" value="root" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"> </property> <property name="dataSource" ref="dataSource" /> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> <bean id="UserDAO" class="dao.UserDAO"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <bean id="service" class="services.UserService"> <property name="userDao"> <ref bean="UserDAO" /> </property> </bean> <bean name="/login" class="com.stu.struts.action.LoginAction"> <property name="service"> <ref bean="service" /> </property> </bean> </beans> [color=#FF0000]hibernate.cfg.xml:[/color] <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <!-- Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration> <session-factory> <property name="dialect"> org.hibernate.dialect.MySQLDialect </property> <property name="connection.url"> jdbc:mysql://localhost:3306/mytest </property> <property name="connection.username">root</property> <property name="connection.password">root</property> <property name="connection.driver_class"> com.mysql.jdbc.Driver </property> <property name="myeclipse.connection.profile">mysql</property> <mapping resource="dong/User.hbm.xml" /> </session-factory> </hibernate-configuration> 十二月 06, 2015 3:39:14 下午 org.apache.catalina.core.StandardContext startInternal 严重: Error listenerStart ERROR [ContextLoader] - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.service.UnknownUnwrapTypeException: Cannot unwrap to requested type [javax.sql.DataSource]
ssh整合hibernatetemplate不允许写的问题
struts2,hibernate5,spring4整合,以前没有遇到过,整整搞了一天了没找出原因,哪位大神帮帮忙: 页面Struts提示的错误信息如下: ![错误信息](https://img-ask.csdn.net/upload/201510/05/1443975228_98251.png) spring的beans.xml里是这么配置的 ``` <bean id="sessionfactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="packagesToScan"> <value>cn.itcast.oa.domain</value> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> <!-- org.hibernate.dialect.OracleDialect --> org.hibernate.dialect.MySQL5Dialect </prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="cache.use_query_cache">true</prop> <prop key="cache.use_second_level_cache">true</prop> <prop key="cache.region.factory_class">org.hibernate.cache.EhCacheRegionFactory</prop> </props> </property> </bean> <bean id="txManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionfactory" /> </bean> <tx:advice id="tad" transaction-manager="txManager"> <tx:attributes> <tx:method name="find*" read-only="true" /> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut expression="execution(* cn.itcast.oa.service.impl.*.*(..))" id="service1" /> <aop:advisor advice-ref="tad" pointcut-ref="service1" /> </aop:config> <bean name="template" class="org.springframework.orm.hibernate5.HibernateTemplate"> <property name="sessionFactory" ref="sessionfactory"> </property> </bean> ``` 代码里的结构是HT类接受spring注入template,service基类(泛型类)继承HT并且实现DAOsupport接口(这个接口是泛型接口),service实现类继承service基类并且实现DAOsupport的子接口,具体代码如下: HT类 ```@Component public class HT { private HibernateTemplate ht; public HibernateTemplate getHt() { return ht; } @Resource public void setHt(HibernateTemplate ht) { this.ht = ht; } } ``` DAOsupport接口如下 ```public interface DAOSupport<T> { public void save(T t); } ``` 基类代码如下: ```public class DAOsupportImpl<T> extends HT implements DAOSupport<T> { private Class<T> clazz; public DAOsupportImpl() { super(); ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass(); // 获取当前new的对象的 // 泛型的父类 // 类型 clazz = (Class<T>) pt.getActualTypeArguments()[0]; // 获取第一个类型参数的真实类型 System.out.println("clazz ---> " + clazz); } @Override public void save(T t) { System.out.println("到dao"+t.getClass()); getHt().save(t); } public Class<T> getClazz() { return clazz; } public void setClazz(Class<T> clazz) { this.clazz = clazz; } } ``` service实现类代码如下 ```@Component public class UserServiceImpl extends DAOsupportImpl<User> implements UserService { } ``` action中的方法如下 ``` public String save() { //System.out.println("到action"); ActionContext.getContext().getApplication().remove("users"); this.userService.save(getModel());//model是user的一个实例 return "list"; } ```
struts2+spring整合后Action实现SessionAware后获取不到Session
<p>以下是Action实现的方法,下面只是贴出了Action的实现,代码测试过没问题,但只要运行到设置Session的地方就通不过,但也不报错,通过检测发现设置session时通过IOC方式注入的map形式的session未获取到,也就是getSession得到的是null,所以程序执行不了,看看哪位能看出下面程序问题的指点一下,我找了两天了,对照struts2中的示例也没发现哪里有问题,在此先谢谢了!</p> <p>public class ManagerAction extends ActionSupport implements SessionAware{ <br>IGxManagerService gxManagerService=null; <br><br> private String username = null; <br><br>private String password = null; <br><br>private Map session; <br><br>public void setSession(Map value) {//实现SessionAware中的setSession方法,通过IOC方式注入Session <br>session = value; <br>} <br><br><span style="color: #0000ff;">public Map getSession() { //获取map形式的session集合<br>return session; <br>}</span> <br><br>         public String getUsername() { <br>return username; <br>} <br><br>public void setUsername(String username) { <br>this.username = username; <br>} <br><br>public String getPassword() { <br>return password; <br>} <br><br>public void setPassword(String password) { <br>this.password = password; <br>} <br>public GxManager getManagerSessionInfo() { <br>return (GxManager) getSession().get(WebConstants.WEB_MANAGER_KEY); <br>} <br><br>/** <br>* &lt;p&gt; <br>* Store new reference to GxManager Object. <br>* &lt;/p&gt; <br>* <br>* @param GxManager <br>*            GxManager object for authenticated GxManager <br>*/ <br>public void setManagerSessionInfo(GxManager gxManger) { <br>getSession().put(WebConstants.WEB_MANAGER_KEY, gxManger); <br>} <br>public IGxManagerService getGxManagerService() { <br>return gxManagerService; <br>} <br><br>public void setGxManagerService(IGxManagerService gxManagerService) { <br>this.gxManagerService = gxManagerService; <br>} <br><br>public String login() { <br>GxManager gxManager = null; <br>try { <br>gxManager = gxManagerService.checkLogin(getUsername(),getPassword()); <br>} catch (Exception e) { <br>// TODO Auto-generated catch block <br>e.printStackTrace(); <br>} <br>if (gxManager != null) { <br><span style="color: #ff0000;">setManagerSessionInfo(gxManager);</span><span style="color: #ff0000;"> //此处出现问题,检测的结果是调用上面蓝色的getSession时获取到的值为NULL</span><br>} <br>if (hasErrors()) { <br>                      return INPUT; <br>                   } <br>return SUCCESS; <br>} <br><br>}</p> <p> </p><br /><strong>问题补充:</strong><br />配置文件都应该是没问题的,因为只要我把setManagerSessionInfo(gxManager)这一句注释掉程序就可以正常执行的<br /><strong>问题补充:</strong><br />下面这个是spring的配置文件 <br />&lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt; <br /> &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"&gt; <br /> &lt;/property&gt; <br /> &lt;property name="url" value="jdbc:mysql://localhost:3306/test"&gt;&lt;/property&gt; <br /> &lt;property name="username" value="root"&gt;&lt;/property&gt; <br /> &lt;property name="password" value="root"&gt;&lt;/property&gt; <br /> &lt;/bean&gt; <br /> <br /> &lt;bean id="sessionFactory" <br /> class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt; <br /> &lt;property name="dataSource"&gt; <br /> &lt;ref bean="dataSource" /&gt; <br /> &lt;/property&gt; <br /> &lt;property name="hibernateProperties"&gt; <br /> &lt;props&gt; <br /> &lt;prop key="hibernate.dialect"&gt; <br /> org.hibernate.dialect.MySQLDialect <br /> &lt;/prop&gt; <br /> &lt;prop key="hibernate.show_sql"&gt;false&lt;/prop&gt; <br /> &lt;/props&gt; <br /> &lt;/property&gt; <br /> &lt;property name="mappingResources"&gt; <br /> &lt;list&gt; <br /> &lt;value&gt;com/gx/entity/member/GxUserinfo.hbm.xml&lt;/value&gt; <br /> &lt;value&gt;com/gx/entity/GxManager.hbm.xml&lt;/value&gt;&lt;/list&gt; <br /> &lt;/property&gt; <br /> &lt;/bean&gt; <br /> &lt;bean id="myTransactionManager" <br /> class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt; <br /> &lt;property name="sessionFactory"&gt; <br /> &lt;ref local="sessionFactory" /&gt; <br /> &lt;/property&gt; <br /> &lt;/bean&gt; <br /> <br /> &lt;bean id="transationInterceptor" <br /> class="org.springframework.transaction.interceptor.TransactionInterceptor"&gt; <br /> &lt;property name="transactionManager" ref="myTransactionManager" /&gt; <br /> &lt;property name="transactionAttributes"&gt; <br /> &lt;props&gt; <br /> &lt;prop key="save*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt; <br /> &lt;prop key="update*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt; <br /> &lt;prop key="delete*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt; <br /> &lt;prop key="Save*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt; <br /> &lt;prop key="merge*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt; <br /> &lt;prop key="shield*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt; <br /> &lt;/props&gt; <br /> &lt;/property&gt; <br /> <br /> &lt;/bean&gt; <br /> <br /> &lt;bean <br /> class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"&gt; <br /> &lt;property name="beanNames"&gt; <br /> &lt;value&gt;*DAO,*Service,*Services&lt;/value&gt; <br /> &lt;/property&gt; <br /> &lt;property name="interceptorNames"&gt; <br /> &lt;list&gt; <br /> &lt;value&gt;transationInterceptor&lt;/value&gt; <br /> &lt;/list&gt; <br /> &lt;/property&gt; <br /> &lt;/bean&gt; <br />&nbsp;&nbsp;&nbsp; <br /> &lt;bean id="GxManagerDAO" class="com.gx.dao.imp.GxManagerDAO"&gt; <br /> &lt;property name="sessionFactory"&gt; <br /> &lt;ref bean="sessionFactory" /&gt; <br /> &lt;/property&gt; <br /> &lt;/bean&gt; <br /> &lt;bean id="GxManagerService" class="com.gx.service.imp.GxManagerService"&gt; <br /> &nbsp;&nbsp;&nbsp; &lt;property name="gxManagerDAO"&gt; <br /> &lt;ref bean="GxManagerDAO" /&gt; <br /> &lt;/property&gt; <br /> &lt;/bean&gt; <br /> &lt;bean id="ManagerAction" class="com.gx.web.action.ManagerAction"&gt; <br /> &nbsp;&nbsp;&nbsp; &lt;property name="gxManagerService"&gt; <br /> &lt;ref bean="GxManagerService" /&gt; <br /> &lt;/property&gt; <br /> &lt;/bean&gt; <br /> &lt;/beans&gt;<br /><strong>问题补充:</strong><br />public class ManagerAction extends ActionSupport implements SessionAware <br />方法中已经实现了SessionAware接口,session应该是由struts2中的IOC方式自动注入的,应该不需要通过spring进行注入才是的!<br /><strong>问题补充:</strong><br />那应该怎么注入呢,因为如果只单独使用struts2上面的方式是可以获取到session的,因为上面是struts2中所说的通过实现sessionAware以IOC的方式获取struts2中封闭的map形式的底层session集合,上面之所以得不到,应该是由于struts2整合了spring的原因,但具体在spring中如何注入就不知道怎么做了!
struts2-2.2.1+hibernate3.3.1+spring2.5.6整合
我首先整合的hibernate和spring,通过测试是成功的。然后开始struts2的整合,出现错误,请各位帮忙看下,是怎么个情况?涉及到的配置文件和错误如下: [color=darkred][b]web.xml[/b][/color] <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <!-- 指定spring的配置文件路径 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <!-- 实例化spring容器 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> =============================================================================================== [color=darkred][b]spring配置文件applicationContext.xml[/b][/color] <?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/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <context:component-scan base-package="com.ssh"></context:component-scan> <!-- 配置数据源 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="org.gjt.mm.mysql.Driver"></property> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=UTF-8"></property> <property name="user" value="root"></property> <property name="password" value="root"></property> <property name="initialPoolSize" value="1"></property> <property name="minPoolSize" value="1"></property> <property name="maxPoolSize" value="300"></property> <property name="maxIdleTime" value="60"></property> <property name="acquireIncrement" value="5"></property> <property name="idleConnectionTestPeriod" value="60"></property> </bean> <!-- 配置sessionFactory --> <bean id="sf" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="mappingResources"> <list> <value>com/ssh/bean/Employee.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.MySQL5Dialect hibernate.hbm2ddl.auto=update hibernate.show_sql=true hibernate.format_sql=false </value> </property> </bean> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sf"></property> </bean> <tx:annotation-driven transaction-manager="txManager"/> <bean id="employeeservice" class="com.ssh.service.EmployeeService"></bean> </beans> ==================================================================================================== [color=darkred][b]struts.xml[/b][/color] <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <!-- <constant name="struts.objectFactory" value="spring"></constant>--> <package name="employee" namespace="/employee" extends="struts-default"> <action name="list" class="ermployeeAction"> <result name="list">WEB-INF/page/employee.jsp</result> </action> </package> </struts> =============================================================================================== 错误: Context initialization failed - <2011-03-11 12:23:39,765> ERROR (ContextLoader.java:215) org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeAction': Injection of resource fields failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.ssh.impl.EmployeeImpl] is defined: expected single matching bean but found 2: [employeeService, employeeservice] at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessAfterInstantiation(CommonAnnotationBeanPostProcessor.java:292) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:959) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920) at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022) at org.apache.catalina.core.StandardHost.start(StandardHost.java:736) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:448) at org.apache.catalina.core.StandardServer.start(StandardServer.java:700) at org.apache.catalina.startup.Catalina.start(Catalina.java:552) 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.catalina.startup.Bootstrap.start(Bootstrap.java:295) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433) Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.ssh.impl.EmployeeImpl] is defined: expected single matching bean but found 2: [employeeService, employeeservice] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:621) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:431) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:409) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:537) at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:180) at org.springframework.beans.factory.annotation.InjectionMetadata.injectFields(InjectionMetadata.java:105) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessAfterInstantiation(CommonAnnotationBeanPostProcessor.java:289) ... 40 more 这里只是进行一个框架整合的简单测试,涉及的文件不多,一个action 和关于业务逻辑的一个接口以及实现该接口的类。
爬虫福利二 之 妹子图网MM批量下载
爬虫福利一:27报网MM批量下载    点击 看了本文,相信大家对爬虫一定会产生强烈的兴趣,激励自己去学习爬虫,在这里提前祝:大家学有所成! 目标网站:妹子图网 环境:Python3.x 相关第三方模块:requests、beautifulsoup4 Re:各位在测试时只需要将代码里的变量 path 指定为你当前系统要保存的路径,使用 python xxx.py 或IDE运行即可。
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过
Elastic:菜鸟上手指南
您们好,我是Elastic的刘晓国。如果大家想开始学习Elastic的话,那么这里将是你理想的学习园地。在我的博客几乎涵盖了你想学习的许多方面。在这里,我来讲述一下作为一个菜鸟该如何阅读我的这些博客文章。 我们可以按照如下的步骤来学习: 1) Elasticsearch简介:对Elasticsearch做了一个简单的介绍 2) Elasticsearch中的一些重要概念:cluster, n
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、PDF搜索网站推荐 对于大部
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看
Java知识体系最强总结(2020版)
更新于2020-01-05 18:08:00 本人从事Java开发已多年,平时有记录问题解决方案和总结知识点的习惯,整理了一些有关Java的知识体系,这不是最终版,会不定期的更新。也算是记录自己在从事编程工作的成长足迹,通过博客可以促进博主与阅读者的共同进步,结交更多志同道合的朋友。特此分享给大家,本人见识有限,写的博客难免有错误或者疏忽的地方,还望各位大佬指点,在此表示感激不尽。 整理的Ja
计算机专业的书普遍都这么贵,你们都是怎么获取资源的?
介绍几个可以下载编程电子书籍的网站。 1.Github Github上编程书资源很多,你可以根据类型和语言去搜索。推荐几个热门的: free-programming-books-zh_CN:58K 星的GitHub,编程语言、WEB、函数、大数据、操作系统、在线课程、数据库相关书籍应有尽有,共有几百本。 Go语言高级编程:涵盖CGO,Go汇编语言,RPC实现,Protobuf插件实现,Web框架实
卸载 x 雷某度!GitHub 标星 1.5w+,从此我只用这款全能高速下载工具!
作者 | Rocky0429 来源 | Python空间 大家好,我是 Rocky0429,一个喜欢在网上收集各种资源的蒟蒻… 网上资源眼花缭乱,下载的方式也同样千奇百怪,比如 BT 下载,磁力链接,网盘资源等等等等,下个资源可真不容易,不一样的方式要用不同的下载软件,因此某比较有名的 x 雷和某度网盘成了我经常使用的工具。 作为一个没有钱的穷鬼,某度网盘几十 kb 的下载速度让我
复习一周,京东+百度一面,不小心都拿了Offer
你知道的越多,你不知道的越多 点赞再看,养成习惯 本文 GitHub https://github.com/JavaFamily 已收录,有一线大厂面试点思维导图,也整理了很多我的文档,欢迎Star和完善,大家面试可以参照考点复习,希望我们一起有点东西。 前言 还记得我上周说的重庆邮电研二的读者么? 、 知道他拿了Offer之后我也很开心,我就想把它的面试经历和面试题分享出来
毕业5年,我问遍了身边的大佬,总结了他们的学习方法
你知道的越多,你不知道的越多 点赞再看,养成习惯 本文 GitHub https://github.com/JavaFamily 已收录,有一线大厂面试点思维导图,也整理了很多我的文档,欢迎Star和完善,大家面试可以参照考点复习,希望我们一起有点东西。 前言 很多次小伙伴问到学习方法,我也很想写这样的一篇文章来跟大家讨论下关于学习方法这件事情。 其实学习方法这个事情,我没啥发言权
推荐10个堪称神器的学习网站
每天都会收到很多读者的私信,问我:“二哥,有什么推荐的学习网站吗?最近很浮躁,手头的一些网站都看烦了,想看看二哥这里有什么新鲜货。” 今天一早做了个恶梦,梦到被老板辞退了。虽然说在我们公司,只有我辞退老板的份,没有老板辞退我这一说,但是还是被吓得 4 点多都起来了。(主要是因为我掌握着公司所有的核心源码,哈哈哈) 既然 4 点多起来,就得好好利用起来。于是我就挑选了 10 个堪称神器的学习网站,推
这些软件太强了,Windows必装!尤其程序员!
Windows可谓是大多数人的生产力工具,集娱乐办公于一体,虽然在程序员这个群体中都说苹果是信仰,但是大部分不都是从Windows过来的,而且现在依然有很多的程序员用Windows。 所以,今天我就把我私藏的Windows必装的软件分享给大家,如果有一个你没有用过甚至没有听过,那你就赚了......,这可都是提升你幸福感的高效率生产力工具哦! 走起!...... NO、1 ScreenToGif 屏幕,摄像头和
大学四年因为知道了这32个网站,我成了别人眼中的大神!
依稀记得,毕业那天,我们导员发给我毕业证的时候对我说“你可是咱们系的风云人物啊”,哎呀,别提当时多开心啦......,嗯,我们导员是所有导员中最帅的一个,真的...... 不过,导员说的是实话,很多人都叫我大神的,为啥,因为我知道这32个网站啊,你说强不强......,这次是绝对的干货,看好啦,走起来! PS:每个网站都是学计算机混互联网必须知道的,真的牛杯,我就不过多介绍了,大家自行探索,觉得没用的,尽管留言吐槽吧?
看完这篇HTTP,跟面试官扯皮就没问题了
我是一名程序员,我的主要编程语言是 Java,我更是一名 Web 开发人员,所以我必须要了解 HTTP,所以本篇文章就来带你从 HTTP 入门到进阶,看完让你有一种恍然大悟、醍醐灌顶的感觉。 最初在有网络之前,我们的电脑都是单机的,单机系统是孤立的,我还记得 05 年前那会儿家里有个电脑,想打电脑游戏还得两个人在一个电脑上玩儿,及其不方便。我就想为什么家里人不让上网,我的同学 xxx 家里有网,每
史上最全的IDEA快捷键总结
写在前面: 我是 扬帆向海,这个昵称来源于我的名字以及女朋友的名字。我热爱技术、热爱开源、热爱编程。技术是开源的、知识是共享的。 这博客是对自己学习的一点点总结及记录,如果您对 Java、算法 感兴趣,可以关注我的动态,我们一起学习。 用知识改变命运,让我们的家人过上更好的生活。 相关文章: Idea 中最常用的10款插件,提高开发效率 Eclipse 最牛逼的 10 组快捷键,提高开发效率
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
你知道的越多,你不知道的越多 点赞再看,养成习惯 本文 GitHub https://github.com/JavaFamily 已收录,有一线大厂面试点思维导图,也整理了很多我的文档,欢迎Star和完善,大家面试可以参照考点复习,希望我们一起有点东西。 前前言 为啥今天有个前前言呢? 因为你们的丙丙啊,昨天有牌面了哟,直接被微信官方推荐,知乎推荐,也就仅仅是还行吧(心里乐开花)
一文带你看清 HTTP 所有概念
上一篇文章我们大致讲解了一下 HTTP 的基本特征和使用,大家反响很不错,那么本篇文章我们就来深究一下 HTTP 的特性。我们接着上篇文章没有说完的 HTTP 标头继续来介绍(此篇文章会介绍所有标头的概念,但没有深入底层) HTTP 标头 先来回顾一下 HTTP1.1 标头都有哪几种 HTTP 1.1 的标头主要分为四种,通用标头、实体标头、请求标头、响应标头,现在我们来对这几种标头进行介绍 通用
作为一个程序员,CPU的这些硬核知识你必须会!
CPU对每个程序员来说,是个既熟悉又陌生的东西? 如果你只知道CPU是中央处理器的话,那可能对你并没有什么用,那么作为程序员的我们,必须要搞懂的就是CPU这家伙是如何运行的,尤其要搞懂它里面的寄存器是怎么一回事,因为这将让你从底层明白程序的运行机制。 随我一起,来好好认识下CPU这货吧 把CPU掰开来看 对于CPU来说,我们首先就要搞明白它是怎么回事,也就是它的内部构造,当然,CPU那么牛的一个东
【综合篇】浏览器的工作原理:浏览器幕后揭秘
web(给达达前端加星标,提升前端技能) 了解浏览器是如何工作的,能够让你站在更高的角度去理解前端 浏览器的发展历程的三大路线,第一是应用程序web化,第二是web应用移动化,第三是web操作系统化。是不是有点不直白。 应用程序web化就是随着现在技术的发展,现在越来越多的应用转向了浏览器与服务器,就是B/S架构;web应用移动化,就是在移动设备应用,什么是移动设备呢。 “移动设备:
破14亿,Python分析我国存在哪些人口危机!
2020年1月17日,国家统计局发布了2019年国民经济报告,报告中指出我国人口突破14亿。 猪哥的朋友圈被14亿人口刷屏,但是很多人并没有看到我国复杂的人口问题:老龄化、男女比例失衡、生育率下降、人口红利下降等。 今天我们就来分析一下我们国家的人口数据吧! 更多有趣分析教程,扫描下方二维码关注vx公号「裸睡的猪」 即可查看! 一、背景 1.人口突破14亿 2020年1月17日,国家统计局发布
作为一个程序员,内存和磁盘的这些事情,你不得不知道啊!!!
截止目前,我已经分享了如下几篇文章: 一个程序在计算机中是如何运行的?超级干货!!! 作为一个程序员,CPU的这些硬核知识你必须会! 作为一个程序员,内存的这些硬核知识你必须懂! 这些知识可以说是我们之前都不太重视的基础知识,可能大家在上大学的时候都学习过了,但是嘞,当时由于老师讲解的没那么有趣,又加上这些知识本身就比较枯燥,所以嘞,大家当初几乎等于没学。 再说啦,学习这些,也看不出来有什么用啊!
这个世界上人真的分三六九等,你信吗?
偶然间,在知乎上看到一个问题 一时间,勾起了我深深的回忆。 以前在厂里打过两次工,做过家教,干过辅导班,做过中介。零下几度的晚上,贴过广告,满脸、满手地长冻疮。 再回首那段岁月,虽然苦,但让我学会了坚持和忍耐。让我明白了,在这个世界上,无论环境多么的恶劣,只要心存希望,星星之火,亦可燎原。 下文是原回答,希望能对你能有所启发。 如果我说,这个世界上人真的分三六九等,...
B 站上有哪些很好的学习资源?
哇说起B站,在小九眼里就是宝藏般的存在,放年假宅在家时一天刷6、7个小时不在话下,更别提今年的跨年晚会,我简直是跪着看完的!! 最早大家聚在在B站是为了追番,再后来我在上面刷欧美新歌和漂亮小姐姐的舞蹈视频,最近两年我和周围的朋友们已经把B站当作学习教室了,而且学习成本还免费,真是个励志的好平台ヽ(.◕ฺˇд ˇ◕ฺ;)ノ 下面我们就来盘点一下B站上优质的学习资源: 综合类 Oeasy: 综合...
死磕Lambda表达式(二):Lambda的使用
在哪使用Lambda表达式?怎么样正确的使用Lambda表达式?
史上最牛逼的 Eclipse 快捷键,提高开发效率!
如果你在使用IDEA,请参考博主另外的一篇idea快捷键的博客。
在三线城市工作爽吗?
我是一名程序员,从正值青春年华的 24 岁回到三线城市洛阳工作,至今已经 6 年有余。一不小心又暴露了自己的实际年龄,但老读者都知道,我驻颜有术,上次去看房子,业务员肯定地说:“小哥肯定比我小,我今年还不到 24。”我只好强颜欢笑:“你说得对。” 从我拥有记忆到现在进入而立之年,我觉得,我做过最明智的选择有下面三个: 1)高中三年,和一位女同学保持着算不上朋友的冷淡关系;大学半年,把这位女同学追到...
CSS操作之你不得不知的一些小技巧(一)ヾ(Ő∀Ő๑)ノ太棒了!!
目录 CSS单行/多行文本,超出隐藏并显示省略号 1. CSS单行/多行文本,超出隐藏并显示省略号 方法一:使用CSS属性 单行文本溢出显示省略号 width: 100px; overflow: hidden; text-overflow:ellipsis; //文本溢出显示省略号 white-space: nowrap; //文本不会换...
强烈推荐 10 款珍藏的 Chrome 浏览器插件
Firebug 的年代,我是火狐(Mozilla Firefox)浏览器的死忠;但后来不知道为什么,该插件停止了开发,导致我不得不寻求一个新的网页开发工具。那段时间,不少人开始推荐 Chrome 浏览器,我想那就试试吧,期初我觉得用起来很别扭,毕竟我不是一个“喜新厌旧”的人。但用的次数越来越多,也就习惯了。 Chrome 浏览器有一个好处,就是插件极其丰富,只有你想不到的,没有你找不到的,这恐怕是...
我以为我对数据库索引十分了解,直到我遇到了阿里面试官。
索引的数据结构分析,数据库面试到索引最常见的问题分析,我总结了一下。
相关热词 c# singleton c#中类的默认值是 c#各种进制之间的转换 c# 正则表达式保留汉字 c#后台跨域 c#基础代码大全 c#指定combox选择 c#关系 mono c# 相差毫秒 用c#做一个简易计算器
立即提问