ssh框架使用动态数据源通过aop动态切换数据源数据源没有切换成功。

在开启事务情况下进入service1使用db1数据源,执行service中调用了service2使用db2数据源,在service2中第一次执行sql成功,第二次使用createSQLQuery
执行sql报错,报错提示为:db1中这个表不存在。

在service2中我明明是用着db2的数据源,可是却报db1不存在表。
求大佬帮忙。
两个service都有事务注解,是因为事务才报的错吗?还是是因为createSQLQuery不支持多数据源呀?

图片说明图片说明图片说明

1个回答

不要在dao使用aop切换数据源,因为你进入service方法,事物开启了,你在dao切换,肯定切换不了,
解决方案是:AOP拦截service的接口 进行切换数据源

w549923414
假装大牛 就是在service层做的,前两次查询正常数据源也使用正确,执行只有执行createSQLQuery
大约一年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
spring+hibernate配置多数据源动态切换,java实体如何和各个数据库实例映射?

我的一个javaweb项目,需要用到多个数据源,都是oracle实例,我用spring配置了数据源的动态切换。使用AOP在service层做拦截,然后用注解DataSource来标示所要选择的数据源。现在我有一个问题,就是我用数据库操作时,hibernate是面向对象的,我该如何将不同的java实体映射到不同的数据源上(不同数据库表结构不同)。比如一个product包中的java实体映射到数据库1,cart包中的实体映射到数据库2。如何做到呢?

SSH框架不能实现更新问题

先来spring配置 <?xml version="1.0" encoding="UTF-8" ?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" default-autowire="byName" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.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"> <!-- 上下文注释配置 --> <context:annotation-config /> <context:component-scan base-package="com.ffour.yixing.entity" /> <!-- 引入项目配置属性文件 --> <context:property-placeholder location="classpath:db.properties" /> <!-- 配置数据源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <!-- 数据库驱动类 --> <property name="driverClassName" value="${database.driverClassName}" /> <property name="url" value="${database.url}" /> <property name="username" value="${database.username}" /> <property name="password" value="${database.password}" /> </bean> <!-- 会话工厂 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:hibernate.cfg.xml" /> </bean> <!-- 上下文组件扫描 --> <context:component-scan base-package="com.ffour.yixing"></context:component-scan> <!-- 定义事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" > <property name="dataSource" ref="dataSource"/> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:annotation-driven transaction-manager="transactionManager"/> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" propagation="REQUIRED" read-only="true" /> <tx:method name="find*" propagation="REQUIRED" read-only="true" /> <tx:method name="list*" propagation="REQUIRED" read-only="true" /> <tx:method name="load*" propagation="REQUIRED" read-only="true" /> <tx:method name="select*" propagation="REQUIRED" read-only="true" /> <tx:method name="save*" propagation="REQUIRED" rollback-for="Exception"/> <tx:method name="add*" propagation="REQUIRED" rollback-for="Exception"/> <tx:method name="update*" propagation="REQUIRED" rollback-for="Exception"/> <tx:method name="delete*" propagation="REQUIRED" rollback-for="Exception"/> <!-- 其他方法使用默认的事务设置 --> <tx:method name="*" propagation="REQUIRED"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="interceptorPointCuts" expression="execution(* com.ffour.yixing.service.impl.*Impl.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="interceptorPointCuts" /> </aop:config> <bean id="sysUserInfoDao" class="com.ffour.yixing.dao.impl.SysUserInfoDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="sysUserInfoSV" class="com.ffour.yixing.service.impl.SysUserInfoImpl"> <property name="sysUserInfoDao" ref="sysUserInfoDao"></property> </bean> <bean id="sysStudentUserInfoDao" class="com.ffour.yixing.dao.impl.SysStudentUserInfoDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="sysStudentUserInfoSV" class="com.ffour.yixing.service.impl.SysStudentUserInfoImpl"> <property name="sysStudentUserInfoDao" ref="sysStudentUserInfoDao"></property> </bean> </beans>

怎样以c3p0连接数据源,搭建ssh框架,求大神看看那个地方配置有问题

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <tx:annotation-driven transaction-manager="transactionManager"/> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:jdbc.properties"></property> </bean> <bean id="comboPooledDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${className}"></property> <property name="jdbcUrl" value="${url}"></property> <property name="user" value="${user}"></property> <property name="password" value="${pwd}"></property> </bean> <!-- <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="comboPooledDataSource"></property> </bean> --> <!-- LocalSessionFactoryBean用来读取配置文件 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" value="comboPooledDataSource"/> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!--配置事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <bean id="bookAction" class="com.aaa.action.BookAction"> <property name="bookService" ref="bookService"></property> </bean> <bean id="bookDao" class="com.aaa.dao.BookDao"> <property name="hibernateTemplate" ref="hibernateTemplate"></property> </bean> <bean id="bookService" class="com.aaa.service.BookService"> <property name="bookDao" ref="bookDao"></property> </bean> </beans>

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

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

SSH双数据源运行一段时间 ,远程数据库连接卡死

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" default-autowire="byName"> <!-- spring 与hibernate整合 --> <!-- C3P0数据源配置 --> <bean id="dataSource_oracle" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="oracle.jdbc.driver.OracleDriver"></property> <property name="jdbcUrl" value="jdbc:oracle:oci:@AA"></property> <property name="user" value="zzgh"></property> <property name="password" value="zzgh"></property> <!--连接池中保留的最大连接数 --> <property name="maxPoolSize" value="200"></property> <!--连接池中保留的最小连接数 --> <property name="minPoolSize" value="5"></property> <!--初始化时创建的连接数,应在minPoolSize与maxPoolSize之间取值 --> <property name="initialPoolSize" value="10"></property> <!--隔多少秒检查所有连接池中的空闲连接,默认为0表示不检查 --> <property name="idleConnectionTestPeriod" value="30"></property> <!--最大空闲时间,超过空闲时间的连接将被丢弃 --> <property name="maxIdleTime" value="120"></property> <!--当连接池中的连接用完时,C3P0一次性创建新连接的数目 --> <property name="acquireIncrement" value="3"></property> <!--从数据库获取新连接失败后重复尝试获取的次数 --> <property name="acquireRetryAttempts" value="10"></property> <!--两次连接中间隔时间,单位毫秒 --> <property name="acquireRetryDelay" value="1000"></property> <!--连接关闭时默认将所有未提交的操作回滚 --> <property name="autoCommitOnClose" value="false"></property> <!--用以控制数据源内加载的PreparedStatement数量 --> <property name="maxStatements" value="0"></property> </bean> <bean id="sessionFactory2" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource_oracle"></property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop> </props> </property> </bean> <bean id="dataSource_sql" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="net.sourceforge.jtds.jdbc.Driver" /> <property name="jdbcUrl" value="jdbc:jtds:sqlserver://localhost:1433;DatabaseName=AOTUREGISTER" /> <property name="user" value="sa"></property> <property name="password" value="123321"></property> <!--连接池中保留的最大连接数 --> <property name="maxPoolSize" value="200"></property> <!--连接池中保留的最小连接数 --> <property name="minPoolSize" value="5"></property> <!--初始化时创建的连接数,应在minPoolSize与maxPoolSize之间取值 --> <property name="initialPoolSize" value="10"></property> <!--隔多少秒检查所有连接池中的空闲连接,默认为0表示不检查 --> <property name="idleConnectionTestPeriod" value="30"></property> <!--最大空闲时间,超过空闲时间的连接将被丢弃 --> <property name="maxIdleTime" value="120"></property> <!--当连接池中的连接用完时,C3P0一次性创建新连接的数目 --> <property name="acquireIncrement" value="3"></property> <!--从数据库获取新连接失败后重复尝试获取的次数 --> <property name="acquireRetryAttempts" value="10"></property> <!--两次连接中间隔时间,单位毫秒 --> <property name="acquireRetryDelay" value="1000"></property> <!--连接关闭时默认将所有未提交的操作回滚 --> <property name="autoCommitOnClose" value="false"></property> <!--用以控制数据源内加载的PreparedStatement数量 --> <property name="maxStatements" value="0"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource_sql"></property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> <prop key="hibernate.current_session_context_class">thread</prop> </props> </property> <property name="mappingDirectoryLocations"> <list> <value>classpath:com/jn/entity</value> </list> </property> </bean> <bean id="hibernateUtil" class="com.jn.util.HibernateUtil"></bean> <!-- 声明式事务 --> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:annotation-driven transaction-manager="txManager" proxy-target-class="true" /> </beans> bean配置 <bean scope="prototype" class="com.jn.action.PaientInformationAction" name="paientInformationAction"></bean> <bean scope="prototype" class="com.jn.action.RegisterAction" name="registerAction"></bean> <bean scope="prototype" class="com.jn.action.ComPort" name="comPort"></bean> <bean scope="prototype" class="com.jn.dao.impl.ObjectDaoImpl" name="objectDao"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean scope="prototype" class="com.jn.dao.impl.HISDao" name="hisDao"> <property name="sessionFactory" ref="sessionFactory2"></property> </bean>

SSH2 访问多个数据库出现的问题!经常远程连接不上!

SSH2 框架 系统运行了几个月 现在数据才1W多条 但是关联太多 导致系统显示分页100条记录就很慢 现在接手这个项目很多地方都要重新修改。。 现在框架重新搭的时候碰到一个问题 最痛苦 美国有一台服务器主要是读取其他服务器数据库的所有订单 客户信息,国内服务器连接国外把数据库读取回来。 我用spring 配置了2个数据源 配置信息如下: [code="java"] <bean id="aDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="com.mysql.jdbc.Driver"></property> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/yilainetwork?characterEncoding=utf-8"></property> <property name="user" value="*********"></property> <property name="password" value="*********"></property> <property name="minPoolSize" value="5" ></property> <property name="maxPoolSize" value="50"></property> <property name="maxIdleTime" value="60"></property> <property name="acquireIncrement" value="3"></property> <property name="maxStatements" value="0"></property> <property name="idleConnectionTestPeriod" value="60"></property> <property name="acquireRetryAttempts" value="10"></property> <property name="breakAfterAcquireFailure" value="false"></property> <property name="acquireRetryDelay" value="10000"></property> <property name="testConnectionOnCheckin" value="true"></property> <property name="testConnectionOnCheckout" value="true"></property> </bean> <bean id="bDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="com.mysql.jdbc.Driver"></property> <property name="jdbcUrl" value="jdbc:mysql://*********:3306/yilainetwork?characterEncoding=utf-8"></property> <property name="user" value="*********"></property> <property name="password" value="*********"></property> <property name="minPoolSize" value="5" ></property> <property name="maxPoolSize" value="50"></property> <property name="maxIdleTime" value="60"></property> <property name="acquireIncrement" value="3"></property> <property name="maxStatements" value="0"></property> <property name="idleConnectionTestPeriod" value="60"></property> <property name="acquireRetryAttempts" value="10"></property> <property name="breakAfterAcquireFailure" value="false"></property> <property name="acquireRetryDelay" value="10000"></property> <property name="testConnectionOnCheckin" value="true"></property> <property name="testConnectionOnCheckout" value="true"></property> </bean> [/code] 经常性报错 错误信息 [code="java"] Exception in thread "timerFactory" org.springframework.dao.DataAccessResourceFailureException: could not execute query; nested exception is org.hibernate.exception.JDBCConnectionException: could not execute query at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:625) at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412) at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411) at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:912) at com.yilainetwork.dao.CommonDao.findByHqlC(CommonDao.java:96) 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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy16.findByHqlC(Unknown Source) at com.yilainetwork.service.impl.OrdersService.findOrdersC(OrdersService.java:229) at com.yilainetwork.util.testConnectionData.run(testConnectionData.java:31) at java.util.TimerThread.mainLoop(Timer.java:512) at java.util.TimerThread.run(Timer.java:462) Caused by: org.hibernate.exception.JDBCConnectionException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:97) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.loader.Loader.doList(Loader.java:2235) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129) at org.hibernate.loader.Loader.list(Loader.java:2124) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1149) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:921) at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:1) at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406) ... 20 more Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Last packet sent to the server was 84640 ms ago. 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.SQLError.createCommunicationsException(SQLError.java:1074) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3009) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2895) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3438) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2554) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1761) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1912) at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208) at org.hibernate.loader.Loader.getResultSet(Loader.java:1812) at org.hibernate.loader.Loader.doQuery(Loader.java:697) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) at org.hibernate.loader.Loader.doList(Loader.java:2232) ... 30 more Caused by: java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:168) 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:2452) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2906) ... 43 more [/code] 或者前面一样最后的错误信息不是Connection reset [code="java"] Caused by: java.io.EOFException: Can not read response from server. Expected to read 255 bytes, read 0 bytes before connection was unexpectedly lost. at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2455) at com.mysql.jdbc.MysqlIO.nextRowFast(MysqlIO.java:1626) ... 47 more [/code] 或者报下面这个错误!! [code="java"] Exception in thread "timerFactory" org.springframework.transaction.TransactionSystemException: Could not commit Hibernate transaction; nested exception is org.hibernate.TransactionException: JDBC commit failed at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:660) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:412) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy16.findByHqlC(Unknown Source) at com.yilainetwork.service.impl.OrdersService.findOrdersC(OrdersService.java:229) at com.yilainetwork.util.testConnectionData.run(testConnectionData.java:33) at java.util.TimerThread.mainLoop(Timer.java:512) at java.util.TimerThread.run(Timer.java:462) Caused by: org.hibernate.TransactionException: JDBC commit failed at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:161) at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:656) ... 13 more Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communications link failure during commit(). Transaction resolution unknown. 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:984) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926) at com.mysql.jdbc.ConnectionImpl.commit(ConnectionImpl.java:1569) at com.mchange.v2.c3p0.impl.NewProxyConnection.commit(NewProxyConnection.java:803) at org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JDBCTransaction.java:170) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:146) ... 14 more [/code] 原本读取美国服务器的订单是通过直接JAVA JDBC Connection 来连接 也是会经常报 Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Last packet sent to the server was 84640 ms ago. 这个错误 数据库都能连接上去 但是就是直接SQL的时候 ResultSet rs = pstmt.executeQuery(); 获取ResultSet值的时候报错! 在网上找了一些资料 修改MYSQL wait_timeout 8小时等待 时间 也是不行! 一直测试MYSQL的连接 SPRING 配置的C3P0 连接池参数 还是不行!! 如果用C3P0做连接池的话 执行HQL 错误的几率大!! 如果是执行SQL的话 因为读取订单信息关联3 4张表的信息!!数据得重新封装!!但是还是会报错! 有的时候会报事务没有提交!! Spring 事务配置信息 [code="java"] <!-- 事务管理 --> <!-- Transaction beans start --> <!-- 数据源1事务托管 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="aSessionFactory" /> </property> </bean> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="sav*" propagation="REQUIRED"/> <tx:method name="dele*" propagation="REQUIRED"/> <tx:method name="inse*" propagation="REQUIRED"/> <tx:method name="upda*" propagation="REQUIRED"/> <tx:method name="*" read-only="true"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="allManagerMethod" expression="execution(* com.**.dao.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/> </aop:config> <!-- Transaction beans end --> [/code] 因为Spring 配置了俩个 数据源 我有一个切换数据库的方法 网上找的 事务我就直接还是根据其他人的 这样写! 这个问题 到底应该如何解决!! 我对MYSQL my.ini 的[mysqld]增加了 skip-name-resolve

多数据源spring 报java.lang.NullPointerException

在调用test.java的时候就会报 Exception in thread "main" java.lang.NullPointerException at cn.m_solution.mds.mds40.service.MDS40T01Service.getStudent(MDS40T01Service.java:23) at cn.m_solution.mds.mds40.service.test.main(test.java:13) 请大家一定帮忙,已经弄了两天了 [color=red]moduleContext-sys.xml:[/color] <?xml version="1.0" encoding="UTF-8" ?> <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="ApplicationInfo" class="net.uniuvo.webridger.beans.ApplicationInfo"> <!-- 应用系统名称 --> <property name="applicationName" value="mds" /> <!-- 允许直接访问的Action列表 --> <property name="directAccessActions"> <list> <value>mds00.do</value> <value>/mds13.do</value> <value>/mds40.do</value> </list> </property> <!-- 禁止访问的扩展名列表 --> <property name="prohibitedExtensions"> <list> <value>js</value> <value>css</value> <value>jsp</value> <value>html</value> </list> </property> <!-- 禁止访问的扩展名中例外的文件列表 --> <property name="restrictionEscapeFiles"> <list> <value>/pages/index.html</value> <value>/pages/mds40/mds40s00.jsp</value> </list> </property> </bean> <!-- +++++++++++++++++++++++++++++++++++++++++ --> <!-- 数据库关联设定(必须) --> <!--此bean告诉Spring去哪找数据库的配置信息,因为有此Bean才出现下面用${}标记来取变量的语句--> <!-- +++++++++++++++++++++++++++++++++++++++++ --> <!-- 这里定义了ibatis的配置文件所在的位置 --> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>/WEB-INF/config/jdbc/jdbc.properties</value> </property> </bean> <!-- <bean id="DataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">--> <bean id="ds0" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName0}" /> <property name="url" value="${jdbc.url0}" /> <property name="username" value="${jdbc.username0}" /> <property name="password" value="${jdbc.password0}" /> </bean> <bean id="ds1" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName1}" /> <property name="url" value="${jdbc.url1}" /> <property name="username" value="${jdbc.username1}" /> <property name="password" value="${jdbc.password1}" /> </bean> <bean id="DataSource" class="net.uniuvo.webridger.dao.DynamicDataSource"> <property name= "targetDataSources"> <map key-type="java.lang.String"> <entry key="ds0" value-ref="ds0"/> <entry key="ds1" value-ref="ds1"/> </map> </property> <property name="defaultTargetDataSource" ref="ds0"/> </bean> <!--这里就声明了具体的事务 --> <bean id="attrSource" class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource"> <property name="properties"> <props> <prop key="execute*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="insert*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="select*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- 定义事务处理拦截器 --> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager"> <ref local="transactionManager" /> </property> <property name="transactionAttributeSource"> <ref local="attrSource" /> </property> </bean> <!-- 定义事务经理 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource"> <ref local="DataSource" /> </property> </bean> <!-- 自动代理 (业务处理Bean的Id) --> <bean id="autoProxy" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="interceptorNames"> <list> <idref bean="transactionInterceptor" /> </list> </property> <property name="beanNames"> <list> <value>*Service</value> </list> </property> </bean> <!-- iBATIS相关设定 --> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation" value="/WEB-INF/sqlMapConfig.xml" /> <property name="dataSource"> <ref bean="DataSource" /> </property> <property name="lobHandler"> <ref local="oracleLobHandler" /> </property> </bean> <!-- 定义DAO --> <!-- 检索用DAO --> <bean id="queryDAO" class="net.uniuvo.webridger.dao.QueryDAOiBatisImpl"> <property name="sqlMapClient"> <ref local="sqlMapClient" /> </property> </bean> <!-- 追加 更新 删除用DAO --> <bean id="updateDAO" class="net.uniuvo.webridger.dao.UpdateDAOiBatisImpl"> <property name="sqlMapClient"> <ref local="sqlMapClient" /> </property> </bean> <!--根据sqlMapClien创建一个SqlMapClient模版类--> <bean id="SqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate"> <property name="sqlMapClient"> <ref bean="sqlMapClient" /> </property> </bean> <bean id="nativeJdbcExtractor" lazy-init="true" class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor" /> <bean id="oracleLobHandler" lazy-init="true" class="org.springframework.jdbc.support.lob.OracleLobHandler" > <property name="nativeJdbcExtractor"><ref local="nativeJdbcExtractor"/></property> </bean> <!-- 这里就是Facade了,注意,它有个parent属性,就是这个属性,使它的操作受到了事物管理的限制 <bean id="baseFacade" parent="baseTransactionProxy"> <property name="target"> <bean class="facade.BaseFacadeImpl"> 把DAO做为属性注入到Facade中去 <property name="proDao" ref="proDao" /> <property name="errDao" ref="errDao" /> <property name="userDao" ref="userDao" /> <property name="orderDao" ref="orderDao" /> </bean> </property> </bean> --> </beans> [color=red]sqlmapconfig.xml[/color] <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-config-2.dtd"> <sqlMapConfig> <typeHandler jdbcType="BLOB" javaType="[B" callback="org.springframework.orm.ibatis.support.BlobByteArrayTypeHandler"/> <typeHandler jdbcType="CLOB" javaType="java.lang.String" callback="org.springframework.orm.ibatis.support.ClobStringTypeHandler" /> <sqlMap resource="../config/sql/sqlMap-mds.xml" /> <sqlMap resource="../config/sql/sqlMap-mds00.xml" /> <sqlMap resource="../config/sql/sqlMap-mds01.xml" /> <sqlMap resource="../config/sql/sqlMap-mds02.xml" /> <sqlMap resource="../config/sql/sqlMap-mds03.xml" /> <sqlMap resource="../config/sql/sqlMap-mds04.xml" /> <sqlMap resource="../config/sql/sqlMap-mds10.xml" /> <sqlMap resource="../config/sql/sqlMap-mds11.xml" /> <sqlMap resource="../config/sql/sqlMap-mds12.xml" /> <sqlMap resource="../config/sql/sqlMap-mds13.xml" /> <sqlMap resource="../config/sql/sqlMap-mds20.xml" /> <sqlMap resource="../config/sql/sqlMap-mds21.xml" /> <sqlMap resource="../config/sql/sqlMap-mds22.xml" /> <sqlMap resource="../config/sql/sqlMap-mds23.xml" /> <sqlMap resource="../config/sql/sqlMap-mds30.xml" /> <sqlMap resource="../config/sql/sqlMap-mds31.xml" /> <sqlMap resource="../config/sql/sqlMap-mds32.xml" /> <sqlMap resource="../config/sql/sqlMap-mds33.xml" /> <sqlMap resource="../config/sql/sqlMap-mds40.xml" /> </sqlMapConfig> sqlMap-mds40.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd"> <sqlMap > <select id="sql.mds40.001" parameterClass="cn.m_solution.mds.mds40.form.MDS40Form" resultClass="cn.m_solution.mds.mds40.form.MDS40Form"> select syr from vehicle where hpzl = #hpzl# and hphm = #hphm# </select> </sqlMap> MDS40T01Service package cn.m_solution.mds.mds40.service; import org.springframework.orm.ibatis.SqlMapClientTemplate; import cn.m_solution.mds.mds40.form.MDS40Form; public class MDS40T01Service { SqlMapClientTemplate sqlMapClientTemplate; public MDS40Form getStudent(){ MDS40Form form40 = new MDS40Form(); sqlMapClientTemplate.queryForObject("sql.mds40.001",form40); return form40; } /** * @return the sqlMapClientTemplate */ public SqlMapClientTemplate getSqlMapClientTemplate() { return sqlMapClientTemplate; } /** * @param sqlMapClientTemplate the sqlMapClientTemplate to set */ public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) { this.sqlMapClientTemplate = sqlMapClientTemplate; } } test.java package cn.m_solution.mds.mds40.service; import org.springframework.jdbc.core.support.JdbcDaoSupport; public class test extends JdbcDaoSupport{ /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub MDS40T01Service s = new MDS40T01Service(); s.getStudent(); } }

SSH整合 配置文件报错

这是报错 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myaction' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'cn.jbit.ssh.service.impl.PoitestServiceImpl$$EnhancerByCGLIB$$53789971' to required type 'cn.jbit.ssh.service.PoitestService' for property 'ps'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [cn.jbit.ssh.service.impl.PoitestServiceImpl$$EnhancerByCGLIB$$53789971] to required type [cn.jbit.ssh.service.PoitestService] for property 'ps': no matching editors or conversion strategy found at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4961) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5455) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3976) at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:426) at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1345) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519) at java.lang.Thread.run(Thread.java:745) Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'cn.jbit.ssh.service.impl.PoitestServiceImpl$$EnhancerByCGLIB$$53789971' to required type 'cn.jbit.ssh.service.PoitestService' for property 'ps'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [cn.jbit.ssh.service.impl.PoitestServiceImpl$$EnhancerByCGLIB$$53789971] to required type [cn.jbit.ssh.service.PoitestService] for property 'ps': no matching editors or conversion strategy found at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:485) at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:516) at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:510) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1406) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1365) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) ... 22 more Caused by: java.lang.IllegalStateException: Cannot convert value of type [cn.jbit.ssh.service.impl.PoitestServiceImpl$$EnhancerByCGLIB$$53789971] to required type [cn.jbit.ssh.service.PoitestService] for property 'ps': no matching editors or conversion strategy found at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:241) at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:470) ... 28 more 这是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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="org.postgresql.Driver" /> <property name="url" value="jdbc:postgresql://172.23.144.242:5432/poi2016q4" /> <property name="username" value="test" /> <property name="password" value="test" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="myDataSource" /><!-- 数据源 --> <property name="mappingResources"> <list> <value>cn/jbit/ssh/entity/Poitest.hbm.xml</value> <value>cn/jbit/ssh/entity/Kind.hbm.xml</value> <value>cn/jbit/ssh/entity/Xzqh.hbm.xml</value> <value>cn/jbit/ssh/entity/Chain.hbm.xml</value> <value>cn/jbit/ssh/entity/Foodtype.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.Oracle9iDialect </value> </property> </bean> <!--声明事务 --> <!-- 创建事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- 织入增强 --> <aop:config proxy-target-class="true"> <aop:pointcut id="mypoint" expression="execution(* cn.jbit.ssh.service..*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="mypoint" /> </aop:config> <!-- 定义事务 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="del*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="find*" read-only="true"/> <tx:method name="one*" read-only="true"/> <tx:method name="*" propagation="SUPPORTS" read-only="true" /> </tx:attributes> </tx:advice> <!-- 接口注入 --> <bean id="mydao" class="cn.jbit.ssh.dao.impl.KindDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="mydao1" class="cn.jbit.ssh.dao.impl.FoodtypeDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="mydao2" class="cn.jbit.ssh.dao.impl.XzqhDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="mydao3" class="cn.jbit.ssh.dao.impl.ChainDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="mydao5" class="cn.jbit.ssh.dao.impl.PoitestDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- service --> <bean id="myservice" class="cn.jbit.ssh.service.impl.KindServiceImpl"> <property name="dao" ref="mydao"></property> </bean> <bean id="myservice1" class="cn.jbit.ssh.service.impl.FoodtypeServiceImpl"> <property name="dao" ref="mydao1"></property> </bean> <bean id="myservice2" class="cn.jbit.ssh.service.impl.XzqhServiceImpl"> <property name="dao" ref="mydao2"></property> </bean> <bean id="myservice3" class="cn.jbit.ssh.service.impl.ChainServiceImpl"> <property name="dao" ref="mydao3"></property> </bean> <bean id="myservice5" class="cn.jbit.ssh.service.impl.PoitestServiceImpl"> <property name="dao" ref="mydao5"></property> </bean> <!-- action --> <bean id="myaction" class="cn.jbit.ssh.action.KindAction"> <property name="ks" ref="myservice"></property> <property name="fs" ref="myservice1"></property> <property name="xs" ref="myservice2"></property> <property name="cs" ref="myservice3"></property> <property name="ps" ref="myservice5"></property> </bean> </beans>

SSH整合框架中save方法执行的时候会删除原有数据

SSH整合框架中save方法执行的时候会删除原有数据 如: Hibernate: delete from stu_tea where tea_id=? Hibernate: insert into stu_tea (tea_id, stu_id) values (?, ?) 我用的实体类注解方式,多对多关联关系,学生和老师类,执行save的时候每次中间表的关联关系都会被新的关联关系覆盖,看sql语句输出是现实先把原来的删除了,再添加的,检查过自己的配置<prop key="hibernate.hbm2ddl.auto">update</prop>这个确定是update不是create; ## 学生类 ``` package com.cdd.ssh.entity; import java.util.HashSet; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.ManyToMany; @Entity public class Students { @Id @Column(name="sId")//可省略 //设置主键自增 @GeneratedValue(strategy = GenerationType.AUTO) private int sId; private String sName; private String sSex; private int sAge; @ManyToMany(mappedBy="students",cascade={CascadeType.PERSIST}) private Set<Teachers> teachers = new HashSet<Teachers>(); public int getsId() { return sId; } public void setsId(int sId) { this.sId = sId; } public String getsName() { return sName; } public void setsName(String sName) { this.sName = sName; } public String getsSex() { return sSex; } public void setsSex(String sSex) { this.sSex = sSex; } public int getsAge() { return sAge; } public void setsAge(int sAge) { this.sAge = sAge; } public Set<Teachers> getTeachers() { return teachers; } public void setTeachers(Set<Teachers> teachers) { this.teachers = teachers; }; } ``` ## 老师类 ``` package com.cdd.ssh.entity; import java.util.HashSet; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.Table; @Entity //注明实体类对应表明,省略默认使用类名 @Table(name="teachers") public class Teachers { //表明id列 @Id @Column(name="tId")//可省略 //设置主键自增 @GeneratedValue(strategy = GenerationType.AUTO) private int tId; private String tType;//科目 private String tName;//姓名 @ManyToMany(cascade={CascadeType.PERSIST,CascadeType.MERGE}) //设置中间表关联关系 @JoinTable(name="stu_tea", joinColumns ={@JoinColumn(name = "tea_id")}, inverseJoinColumns={@JoinColumn(name="stu_id")}) private Set<Students> students = new HashSet<Students>(); public int gettId() { return tId; } public void settId(int tId) { this.tId = tId; } public String gettType() { return tType; } public void settType(String tType) { this.tType = tType; } public String gettName() { return tName; } public void settName(String tName) { this.tName = tName; } public Set<Students> getStudents() { return students; } public void setStudents(Set<Students> students) { this.students = students; } } ``` ## 这个是dao中的执行方法 ``` public void add(Students student, Teachers teacher) { // TODO Auto-generated method stub Session session = this.getSession(); student.getTeachers().add(teacher); teacher.getStudents().add(student); session.save(teacher); session.save(student); System.out.println(teacher.gettId()); System.out.println(student.getsId()); } ``` 这是我的代码,求大神帮忙啊,一下午了都没弄好, 在这之前我是写的学生和教室类,后来感觉教室不合适,就把教室改成老师类了,配置文件和属性都没有改变,只把用到教室的地方换成了老师; 求大神帮忙 ## 这里是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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd "> <!-- 开启注解 --> <context:annotation-config/> <!-- 扫描包设置 --> <context:component-scan base-package="com.cdd.ssh.*"></context:component-scan> <!--DateSource数据源 使用DBCP连接池--> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/school?useUnicode=true&amp;characterEncoding=UTF8"/> <property name="username" value="root"/> <property name="password" value="chengzi"/> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <!-- 载入实体类 mappingResources --> <property name="packagesToScan"> <value>com.cdd.ssh.entity</value> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> </bean> <!-- 3.~~~~~~~~~~~~~~~~~~~~~~~~~事务配置~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" > <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:annotation-driven transaction-manager="txManager" /> <aop:config> <aop:pointcut expression="execution(public * com.cdd.ssh.service.*.*(..))" id="bussinessService"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="bussinessService" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="txManager" > <tx:attributes> <tx:method name="query*" read-only="true" propagation="NOT_SUPPORTED" /> <!-- get开头的方法不需要在事务中运行 。 有些情况是没有必要使用事务的,比如获取数据。开启事务本身对性能是有一定的影响的--> <tx:method name="*"/> <!-- 其他方法在实务中运行 --> </tx:attributes> </tx:advice> </beans> ```

ssh注解,获取不到server。

web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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>sshTest1</display-name> <!-- 配置Spring的监听器,用于初始化ApplicationContext对象 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext*.xml</param-value> </context-param> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> <!-- 自动扫描action --> <init-param> <param-name>actionPackages</param-name> <param-value>com.lovo</param-value> </init-param> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>login.jsp</welcome-file> </welcome-file-list> </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:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd "> <!--建立数据源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <!-- SQL Server数据驱动 --> <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"> </property> <!-- 数据库地址 --> <property name="url" value="jdbc:sqlserver://localhost:1433; DatabaseName=sshTest"> </property> <property name="username" value="sa"></property> <property name="password" value="123"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <!--配置Hibernate的方言--> <prop key="hibernate.dialect"> org.hibernate.dialect.SQLServerDialect </prop> <!--格式化输出sql语句--> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.use_sql_comments">false</prop> </props> </property> <!--自动扫描实体 --> <property name="packagesToScan" value="com.lovo.*" /> </bean> <!-- 使用 annotation --> <context:annotation-config /> <!-- 自动扫描与装配bean --> <context:component-scan base-package="com.lovo"></context:component-scan> <!-- 采用注释的方式配置 aop --> <aop:aspectj-autoproxy /> <!-- 用注解来实现事务管理 --> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:annotation-driven transaction-manager="txManager"/> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="select*" read-only="true"/> <tx:method name="get*" read-only="true"/> <tx:method name="load*" read-only="true"/> <tx:method name="find*" read-only="true"/> <tx:method name="query*" read-only="true"/> <tx:method name="read*" read-only="true"/> <tx:method name="sync*"/> <tx:method name="*" propagation="REQUIRED" rollback-for="Exception"/> </tx:attributes> </tx:advice> </beans> struts.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <!-- 开启使用开发模式,详细错误提示 --> <constant name="struts.devMode" value="true" /> <!-- 将对象交给spring管理 --> <constant name="struts.objectFactory" value="spring" /> <!-- 指定资源编码类型 --> <constant name="struts.i18n.encoding" value="UTF-8" /> <!-- 指定每次请求到达,重新加载资源文件 --> <constant name="struts.i18n.reload" value="false" /> <!-- 指定每次配置文件更改后,自动重新加载 --> <constant name="struts.configuration.xml.reload" value="false" /> <!-- 默认后缀名 --> <constant name="struts.action.extension" value="action," /> </struts> action package com.lovo.action; import javax.annotation.Resource; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Namespace; import org.apache.struts2.convention.annotation.ParentPackage; import org.apache.struts2.convention.annotation.Result; import org.springframework.stereotype.Controller; import com.lovo.bean.Emp; import com.lovo.service.EmpService; import com.opensymphony.xwork2.ActionSupport; @Namespace("/") @ParentPackage("struts-default") @Controller public class EmpAction extends ActionSupport { @Resource() public Emp emp ; private EmpService empService ; @ Action(value = "empAction", results = { @Result(name = "success", location = "/index.jsp"), @Result(name = "index", location = "/login.jsp")}) public String add() { try { empService.add(emp); } catch (Exception e) { e.printStackTrace(); return "index"; } return "success"; } public Emp getEmp() { return emp; } public void setEmp(Emp emp) { this.emp = emp; } public EmpService getEmpService() { return empService; } public void setEmpService(EmpService empService) { this.empService = empService; } } bean package com.lovo.bean; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @Entity(name="t_emp") public class Emp implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; @Column(name = "pk_name") private String name; @Column(name = "fk_age") private int age; public Emp(){} public Emp(int id, String name, int age) { super(); this.id = id; this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } } dao package com.lovo.dao; import java.util.List; import javax.annotation.Resource; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Repository; import com.lovo.bean.Emp; @Repository("empDao") public class EmpDao { @Resource(name="sessionFactory") private SessionFactory sessionFactory; public void add(Emp emp){ Session session = sessionFactory.getCurrentSession(); session.save(emp); } public List findAll(){ return null; } public SessionFactory getSessionFactory() { return sessionFactory; } public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } } package com.lovo.service; import javax.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.lovo.bean.Emp; import com.lovo.dao.EmpDao; @Service("empService") @Transactional public class EmpService { @Resource(name="empDao") private EmpDao empDao; public EmpService(){} public void add(Emp emp) { empDao.add(emp); } public EmpDao getEmpDao() { return empDao; } public void setEmpDao(EmpDao empDao) { this.empDao = empDao; } } action 访问server的时候,没有访问到server获取数据报空指针异常。 高手帮我看看哪里错了。 。。

maven构建多模块SSH项目配置文件的问题

<p>1、使用maven做为项目构建工具,创建studio、common、oa、system四个模块项目,其中studio为父模块,common为数据库操作模块、Oa 和system为业务模块。common 配置了spring 集成hibernate的基本配置文件common-spring.xml。现在需要在oa模块中建立一个实体类user和user.hbm.xml,请问oa中的oa_spring如何配置,common中如何读取user.hbm.xml?</p> <p>我的common_spring.xml内容如下:</p> <p>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br>&lt;beans xmlns="http://www.springframework.org/schema/beans"<br>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"<br>    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"<br>    xmlns:context="http://www.springframework.org/schema/context"<br>    xsi:schemaLocation="<br>     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd<br>     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd<br>     http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd<br>     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd<br>     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"<br>    default-autowire="byName"&gt;<br>    &lt;!-- enable component scanning (beware that this does not enable mapper <br>        scanning!) --&gt;<br>    &lt;context:component-scan base-package="com.huadainfo.com.dao" /&gt;<br>    &lt;context:component-scan base-package="com.huadainfo.com.dao.impl" /&gt;<br>    &lt;bean<br>        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;<br>        &lt;property name="locations" value="classpath:datasource.properties" /&gt;<br>    &lt;/bean&gt;<br><br>    &lt;!-- 数据源配置 --&gt;<br>    &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"<br>        destroy-method="close"&gt;<br>        &lt;property name="driverClassName" value="${jdbc.driverClassName}"&gt;&lt;/property&gt;<br>        &lt;property name="url" value="${jdbc.url}"&gt;&lt;/property&gt;<br>        &lt;property name="username" value="${jdbc.username}"&gt;&lt;/property&gt;<br>        &lt;property name="password" value="${jdbc.password}"&gt;&lt;/property&gt;<br>        &lt;property name="initialSize" value="10"&gt;&lt;/property&gt;<br>        &lt;property name="maxActive" value="1000"&gt;&lt;/property&gt;<br>        &lt;property name="maxIdle" value="300"&gt;&lt;/property&gt;<br>        &lt;property name="minIdle" value="10"&gt;&lt;/property&gt;<br>        &lt;property name="maxWait" value="10000"&gt;&lt;/property&gt;<br>        &lt;property name="removeAbandoned" value="true" /&gt;<br>        &lt;property name="removeAbandonedTimeout" value="60"/&gt;<br>        &lt;property name="logAbandoned" value="true" /&gt;<br>        &lt;property name="testOnBorrow" value="true"/&gt; <br>           &lt;property name="testWhileIdle" value="true"/&gt; <br>           &lt;property name="validationQuery" value="select getdate()"/&gt; <br>    &lt;/bean&gt;<br><br>    &lt;bean id="sessionFactory"<br>        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;<br>        &lt;property name="dataSource" ref="dataSource" /&gt;<br>        &lt;property name="hibernateProperties"&gt;<br>            &lt;props&gt;<br>                &lt;!-- 指定Hibernate的连接方言 --&gt;<br>                &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.Oracle10gDialect&lt;/prop&gt;<br>                &lt;!-- 配置启动应用时,是否根据Hibernate映射自动创建数据表 --&gt;<br>                &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;<br>                &lt;prop key="hibernate.format_sql"&gt;true&lt;/prop&gt;<br>                &lt;prop key="hibernate.current_session_context_class"&gt;org.springframework.orm.hibernate4.SpringSessionContext<br>                &lt;/prop&gt;<br>                &lt;prop key="hibernate.cache.provider_class"&gt;net.sf.ehcache.hibernate.EhCacheProvider&lt;/prop&gt;<br>                &lt;prop key="hibernate.cache.region.factory_class"&gt;org.hibernate.cache.ehcache.EhCacheRegionFactory<br>                &lt;/prop&gt;<br>            &lt;/props&gt;<br>            <br>        &lt;/property&gt;<br>       <span style="text-decoration: underline;"><span style="background-color: #ff0000;"> &lt;property name="mappingResources"&gt;<br>            &lt;list&gt;<br>                &lt;value&gt;classpath*:com/huadainfo/entity/*.hbm.xml&lt;/value&gt;<br>            &lt;/list&gt;<br>        &lt;/property&gt;</span></span>这部分该怎么写<br>        <br>    &lt;/bean&gt;<br>        &lt;!-- A transaction manager for working with Hibernate SessionFactories --&gt;<br>    &lt;bean id="transactionManager"<br>        class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;<br>        &lt;property name="sessionFactory" ref="sessionFactory" /&gt;<br>    &lt;/bean&gt;<br>    &lt;!-- 配置事务的传播特性 --&gt;<br>    &lt;tx:advice id="txAdvice" transaction-manager="transactionManager"&gt;<br>        &lt;tx:attributes&gt;<br>            &lt;tx:method name="add*" propagation="REQUIRED" read-only="false" /&gt;<br>            &lt;tx:method name="delete*" propagation="REQUIRED" read-only="false" /&gt;<br>            &lt;tx:method name="update*" propagation="REQUIRED" read-only="false" /&gt;<br>            &lt;tx:method name="save*" propagation="REQUIRED" read-only="false" /&gt;<br>            &lt;tx:method name="*" read-only="true" /&gt;<br>        &lt;/tx:attributes&gt;<br>    &lt;/tx:advice&gt;<br>    &lt;!-- 那些类的哪些方法参与事务 --&gt;<br>    &lt;aop:config&gt;<br>        &lt;aop:pointcut id="allManagerMethod"<br>            expression="execution(public * com.huadainfo.common.dao.impl.*.*(..))" /&gt;<br>        &lt;aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice" /&gt;<br>    &lt;/aop:config&gt;<br>    &lt;context:component-scan base-package="com.huadainfo.common.dao" /&gt;<br>    &lt;context:component-scan base-package="com.huadainfo.common.dao.impl" /&gt;<br>    &lt;bean id="hiberDao" class="com.huadainfo.common.dao.impl.HibernateDaoImpl"&gt;<br>        &lt;property name="sessionFactory" ref="sessionFactory"&gt;&lt;/property&gt;<br>    &lt;/bean&gt;<br>&lt;/beans&gt;</p> <p>oa_spring.xml的内容&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br>&lt;beans xmlns="http://www.springframework.org/schema/beans"<br>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"<br>    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"<br>    xmlns:context="http://www.springframework.org/schema/context"<br>    xsi:schemaLocation="<br>     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd<br>     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd<br>     http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd<br>     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd<br>     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"&gt;<br>    &lt;!-- enable component scanning (beware that this does not enable mapper <br>        scanning!) --&gt;<br>   <span style="text-decoration: underline;"><span style="background-color: #ff0000;"> &lt;import resource="classpath*:common_spring.xml"/&gt;</span></span>(引入不到文件)<br>    &lt;bean id="tset" class="com.huadainfo.oa.service.impl.TestNameimpl"&gt;<br>        &lt;property name="hiberDao" ref="hiberDao"&gt;&lt;/property&gt;<br>    &lt;/bean&gt;<br>    <br>&lt;/beans&gt;</p> <p> </p>

ssh的spring 无法注入怎么回事

<strong>UserInfoDAOImpl.java</strong> <br /><pre name="code" class="java">@Service public class UserInfoDAOImpl extends HibernateDaoSupport implements UserInfoDAO { public boolean login(Userinfo userinfo) { boolean isExist = false; Userinfo temp = (Userinfo)this.getHibernateTemplate().find("from Userinfo u where u.username=?", userinfo.getUsername()).get(0); try { if(userinfo.getPassword().equals(temp.getPassword())) isExist = true; } catch(Exception e) { e.printStackTrace(); } System.out.println("id:" + temp.getId()); System.out.println("username:" + temp.getUsername()); System.out.println("password:" + temp.getPassword()); System.out.println("isExist:" + isExist); return isExist; } }</pre> <br /><strong>LoginAction.java</strong> <br /><pre name="code" class="java">@Component @Results(value={ @Result(name="success", location="/login_success.jsp"), @Result(name="fail", location="/Login.jsp") }) public class LoginAction extends ActionSupport { private Userinfo userinfo; @Autowired private UserInfoDAO userInfoDAOImpl; public Userinfo getUserinfo() { return userinfo; } public void setUserinfo(Userinfo userinfo) { this.userinfo = userinfo; } public UserInfoDAO getUserInfoDAOImpl() { return userInfoDAOImpl; } public void setUserInfoDAOImpl(UserInfoDAO userInfoDAOImpl) { System.out.println("注入"); this.userInfoDAOImpl = userInfoDAOImpl; } @Action("login") public String login() { System.out.println("id:" + userinfo.getId()); System.out.println("username:" + userinfo.getUsername()); System.out.println("password:" + userinfo.getPassword()); if(userInfoDAOImpl == null) System.out.println("error"); if(userinfo == null) return "fail"; else return (userInfoDAOImpl.login(userinfo))?"success":"fail"; } }</pre> <br /><strong>applicationContext.xml</strong> <br /><pre name="code" class="java">&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:jee="http://www.springframework.org/schema/jee" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd" default-lazy-init="true"&gt; &lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /&gt; &lt;property name="ignoreResourceNotFound" value="true" /&gt; &lt;property name="locations"&gt; &lt;list&gt; &lt;value&gt;classpath:application.properties&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;context:component-scan base-package="org.sales.dao.Impl" /&gt; &lt;!-- 数据源配置,使用应用内的DBCP数据库连接池 --&gt; &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt; &lt;!-- Connection Info --&gt; &lt;property name="driverClassName" value="${jdbc.driverClassName}" /&gt; &lt;property name="url" value="${jdbc.url}" /&gt; &lt;property name="username" value="${jdbc.username}" /&gt; &lt;property name="password" value="${jdbc.password}" /&gt; &lt;/bean&gt; &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;property name="namingStrategy"&gt; &lt;bean class="org.hibernate.cfg.ImprovedNamingStrategy" /&gt; &lt;/property&gt; &lt;property name="hibernateProperties"&gt; &lt;props&gt; &lt;prop key="hibernate.dialect"&gt;${hibernate.dialect}&lt;/prop&gt; &lt;prop key="hibernate.show_sql"&gt;${hibernate.show_sql}&lt;/prop&gt; &lt;prop key="hibernate.format_sql"&gt;${hibernate.format_sql}&lt;/prop&gt; &lt;prop key="hibernate.cache.provider_class"&gt;org.hibernate.cache.EhCacheProvider&lt;/prop&gt; &lt;!-- &lt;prop key="hibernate.cache.provider_configuration_file_resource_path"&gt;${hibernate.ehcache_config_file}&lt;/prop&gt;--&gt; &lt;/props&gt; &lt;/property&gt; &lt;property name="packagesToScan" value="org.sales.entity" /&gt; &lt;property name="annotatedClasses"&gt; &lt;list&gt; &lt;value&gt;org.sales.entity.Iteminfo&lt;/value&gt; &lt;value&gt;org.sales.entity.Cardinfo&lt;/value&gt; &lt;value&gt;org.sales.entity.Positioninfo&lt;/value&gt; &lt;value&gt;org.sales.entity.Sellinfo&lt;/value&gt; &lt;value&gt;org.sales.entity.Userinfo&lt;/value&gt; &lt;value&gt;org.sales.entity.Voteinfo&lt;/value&gt;&lt;/list&gt; &lt;/property&gt;&lt;/bean&gt; &lt;bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate" &gt; &lt;property name="sessionFactory" ref="sessionFactory"/&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;tx:annotation-driven transaction-manager="transactionManager" /&gt; &lt;bean id="CardinfoDAO" class="org.sales.entity.CardinfoDAO"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="IteminfoDAO" class="org.sales.entity.IteminfoDAO"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="PositioninfoDAO" class="org.sales.entity.PositioninfoDAO"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="SellinfoDAO" class="org.sales.entity.SellinfoDAO"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="UserinfoDAO" class="org.sales.entity.UserinfoDAO"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="VoteinfoDAO" class="org.sales.entity.VoteinfoDAO"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;/beans&gt;</pre> <br /><strong>web.xml</strong> <br /><pre name="code" class="java">&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;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;classpath*:applicationContext.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;filter&gt; &lt;filter-name&gt;OpenSessionInViewFilter&lt;/filter-name&gt; &lt;filter-class&gt;org.springframework.orm.hibernate3.support.OpenSessionInViewFilter&lt;/filter-class&gt; &lt;init-param&gt; &lt;param-name&gt;singleSession&lt;/param-name&gt; &lt;param-value&gt;true&lt;/param-value&gt; &lt;/init-param&gt; &lt;/filter&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;filter&gt; &lt;filter-name&gt;struts2Filter&lt;/filter-name&gt; &lt;filter-class&gt;org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter&lt;/filter-class&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;struts2Filter&lt;/filter-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/filter-mapping&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;OpenSessionInViewFilter&lt;/filter-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/filter-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 />结果在LoginAction.java里面输出: <br />id:null <br />username:username <br />password:USERNAME <br />error <br />说明: error是当被注入的属性为空的时候输出. <br /> 求解~ <br /> <br /><strong>异常(网页上的):</strong> <br />HTTP Status 500 - <br /> <br />type Exception report <br /> <br />message <br /> <br />description The server encountered an internal error () that prevented it from fulfilling this request. <br /> <br />exception <br /> <br />java.lang.NullPointerException <br /> org.sales.actions.LoginAction.login(LoginAction.java:53) <br /> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) <br /> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) <br /> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) <br /> java.lang.reflect.Method.invoke(Method.java:597) <br /> com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441) <br /> com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280) <br /> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)<br/><strong>问题补充</strong><br/><div class="quote_title">xixix2004 写道</div><div class="quote_div">有异常吗。<br /> <br />敢不敢把异常发出来看一下。</div><br />发了<br/><strong>问题补充</strong><br/><div class="quote_title">xixix2004 写道</div><div class="quote_div">好吧,应该不需要异常,请把ACTION里定义的DAO的变量名,变得和xml里定义的BEAN ID属性一致。</div><br />xml里面没有对应的bean,因为使用注释<br/><strong>问题补充</strong><br/><div class="quote_title">yyf365 写道</div><div class="quote_div">可能和楼主的应用写法不太相同,请问你其他的service是否能注入成功呢?,不过是否能试试在applicationContext配置文件中的声明方式换一种呢?<br /><br />如:<br />&lt;bean id="UserInfoDAO"<br /> class="UserInfoDAOImp"&gt;<br /> &lt;/bean&gt;<br />这种形式注入,实例化由spring托管,而在action中只对UserInfoDAO的service进行注入呢<br /><br />而如果出了该service无法注入外,其他其余的service都能正常注入使用,那就另想办法了</div><br /> 可是这种方法有点麻烦,我想实现注释注入,xml文件里面有个扫描的:<br /> &lt;context:component-scan base-package="org.sales.dao.Impl" /&gt;&nbsp; <br/><strong>问题补充</strong><br/>已经试过在 <strong>applicationContext.xml</strong> 文件里面添加<br /><pre name="code" class="xml">&lt;bean id="userInfoDAOImpl" class="org.sales.dao.Impl.UserInfoDAOImpl"&gt; &lt;/bean&gt; &lt;bean id="loginAction" class="org.sales.actions.LoginAction"&gt; &lt;property name="userInfoDAOImpl"&gt; &lt;ref bean="userInfoDAOImpl" /&gt; &lt;/property&gt; &lt;/bean&gt;</pre><br /><br />异常信息一样.<br/><strong>问题补充</strong><br/><div class="quote_title">xixix2004 写道</div><div class="quote_div"><div class="quote_title">bbinglongg 写道</div><div class="quote_div"><div class="quote_title">xixix2004 写道</div><div class="quote_div">好吧,应该不需要异常,请把ACTION里定义的DAO的变量名,变得和xml里定义的BEAN ID属性一致。</div><br />xml里面没有对应的bean,因为使用注释</div><br /><br /><br />你完全没看懂我在说什么。<br /><br /><pre name="code" class="java">private UserInfoDAO userinfoDAO; </pre><br /><pre name="code" class="java"> &lt;bean id="userinfoDAO" class="org.sales.entity.UserinfoDAO"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory" /&gt; &lt;/property&gt; &lt;/bean&gt; </pre><br /><br /><br /><br /></div><br />在它上面有一句:<br /><pre name="code" class="java">@Autowired</pre><br />是自动注入的意思<br/><strong>问题补充</strong><br/><div class="quote_title">xixix2004 写道</div><div class="quote_div">&lt;ref bean="UserInfoDAO" /&gt;这里的REF的BEAN, 写你之前定义的BEAN的ID。你可明白?</div><br />明白<br/><strong>问题补充</strong><br/><div class="quote_title">dwbin 写道</div><div class="quote_div">loginAction没有进行spring托管。<br />这个类spring不会自己进行注入的。你的ssh整合有问题</div><br /><br />那我应该怎么修改呢?<br/><strong>问题补充</strong><br/><div class="quote_title">dwbin 写道</div><div class="quote_div">loginAction没有进行spring托管。<br />这个类spring不会自己进行注入的。你的ssh整合有问题</div><br />在 <pre name="code" class="java">@Autowired</pre> 这个标签里面已经是注入了

spring对多个事务进行统一回滚怎么配置?

如题,在action中注入多个service进行事务操作,要求所有事务一次性成功或者失败?失败数据怎么回滚?

SSH整合过程中:service老是注入失败?

action对象是用struts2产生的,但是service老是注入失败,其他的dao注入正常,在action中通过getbean的方式可以正常获得service beans.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"> <context:annotation-config /> <!-- 分散配置(配置配置文件的位置) --> <context:property-placeholder location= "classpath:jdbc.properties"/> <!-- 生成实例对象要扫描的包,扫描该包,将该包下的注解@Component的类实例化 --> <context:component-scan base-package="com.slg.surveypark.dao.impl,com.slg.surveypark.service.impl,com.slg.surveypark.struts2.action" /> <!-- 配置数据源 --> <bean id="dataSource" destroy-method="close" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${jdbc.driverClassName}" /> <property name="jdbcUrl" value="${jdbc.url}" /> <property name="user" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="maxPoolSize" value="${c3p0.pool.size.max}"/> <property name="minPoolSize" value="${c3p0.pool.size.min}"/> <property name="initialPoolSize" value="${c3p0.pool.size.ini}"/> <property name="acquireIncrement" value="${c3p0.pool.size.increment}"/> </bean> <!--本地会话工程(spring整合 hibernate配置) --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <!-- 扫描一下包内的实体类,有@Entity注解与数据库形成映射 --> <property name="packagesToScan"> <list> <value>com.slg.surveypark.model</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <!-- hibernate.hbm2ddl.auto 当为update时根据java对象生成数据库里的表 --> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> </bean> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <aop:config> <aop:pointcut id="bussinessService" expression="execution(* *..*Service.*(..))" /> <aop:advisor pointcut-ref="bussinessService" advice-ref="txAdvice" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <!-- 写操作 --> <tx:method name="save*" propagation="REQUIRED" isolation="DEFAULT"/> <tx:method name="update*" propagation="REQUIRED" isolation="DEFAULT"/> <tx:method name="delete*" propagation="REQUIRED" isolation="DEFAULT"/> <tx:method name="batch*" propagation="REQUIRED" isolation="DEFAULT"/> <!-- 读操作 --> <tx:method name="load*" propagation="REQUIRED" isolation="DEFAULT" read-only="true"/> <tx:method name="get*" propagation="REQUIRED" isolation="DEFAULT" read-only="true"/> <tx:method name="find*" propagation="REQUIRED" isolation="DEFAULT" read-only="true"/> <tx:method name="*" propagation="REQUIRED" isolation="DEFAULT" /> </tx:attributes> </tx:advice> </beans> ``` struts.xml ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <!-- 主题 --> <constant name="struts.ui.theme" value="simple" /> <!-- 开发模式 --> <constant name="struts.devMode" value="true" /> <package name="surveypark" namespace="/" extends="struts-default"> <action name="RegAction_*" class="com.slg.surveypark.struts2.action.RegAction" method="{1}"> <result name="regPage">/reg.jsp</result> <result name="input">/reg.jsp</result> <result name="success">/index.jsp</result> </action> </package> </struts> ``` action类 ``` package com.slg.surveypark.struts2.action; import javax.annotation.Resource; import org.apache.struts2.interceptor.validation.SkipValidation; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Scope; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.stereotype.Component; import com.slg.surveypark.model.User; import com.slg.surveypark.service.UserService; import com.slg.surveypark.service.impl.UserServiceImpl; import com.slg.surveypark.util.ValidateUtil; //@Component("regaction") //@Scope("prototype") //@Controller public class RegAction extends BaseAction<User> { /** * */ private static final long serialVersionUID = 1L; private User model = new User(); private String confirmPassword; public String getConfirmPassword() { return confirmPassword; } public void setConfirmPassword(String confirmPassword) { this.confirmPassword = confirmPassword; } protected UserService userService; public UserService getUserService() { return userService; } @Resource(name="userService") public void setUserService(UserService userService) { this.userService = userService; } @Override public User getModel() { // TODO Auto-generated method stub return model; } /** * * 这里添加了注解 @SkipValidation 所以会跳过默认的拦截器函数validate() */ @SkipValidation public String toRegPage(){ return "regPage"; } public String doReg(){ userService.saveEntity(model); return SUCCESS; } /** * struts2的默认验证拦截器,所有的action执行前都会执行此函数,除非有跳过注解,如果验证过程有有问题,则 * 终端action的执行过程,返回到struts2配置的“input”指向的页面 */ public void validate(){ if(!ValidateUtil.isValid(model.getEmail())){ addFieldError("email", "email是必填项!"); } if(!ValidateUtil.isValid(model.getNickName())){ addFieldError("nickname", "nickname是必填项!"); } if(!ValidateUtil.isValid(model.getPassword())){ addFieldError("password", "password是必填项!"); } if(hasErrors()){ return ; } if(!model.getPassword().equals(confirmPassword)){ addFieldError("password", "密码不一致!"); return ; } //通过getBean可以获得service // ApplicationContext ctx = new ClassPathXmlApplicationContext("bean.xml"); // userService = (UserService)ctx.getBean("userService"); System.out.println(userService); if(userService.isRegisted(model.getEmail())){ addFieldError("email", "email已占用!"); return; } } } ``` service类 ``` package com.slg.surveypark.service.impl; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import com.slg.surveypark.dao.BaseDao; import com.slg.surveypark.model.User; import com.slg.surveypark.service.UserService; import com.slg.surveypark.util.ValidateUtil; @Component("userService") public class UserServiceImpl extends BaseServiceImpl<User> implements UserService { @Resource(name="userDao") public void setDao(BaseDao<User> dao) { super.setDao(dao); } /** * 判断email是否被注册过 */ public boolean isRegisted(String email){ String hql = "select email from User where email =?"; List<User> users = this.findEntityByHQL(hql, email); return ValidateUtil.isValid(users); } } ``` 求指教

学ssh整合时遇到Error creating bean with name xxx问题,向大家请教

ssh整合,测试时遇到Error creating bean with name xxx问题,这个问题之前看到有很多人问,但是貌似没有什么解决方案。 跪求大佬们指点一二 这是完整的Debug错误信息: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testService' defined in file [E:\MyEclipseworkplace\Test2\WebRoot\WEB-INF\classes\cn\itcast\oa\test\TestService.class]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) at cn.itcast.oa.test.SpringTest.<init>(SpringTest.java:10) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:209) at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:258) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:255) at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer at org.springframework.aop.framework.Cglib2AopProxy.createEnhancer(Cglib2AopProxy.java:228) at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:170) at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:112) at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:476) at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:362) at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:322) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:407) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1426) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) ... 34 more 我的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" 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-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <!-- 自动扫描与装配bean --> <context:component-scan base-package="cn.itcast.oa"></context:component-scan> <!-- 配置数据库连接池(c3p0) --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <!-- 基本信息 --> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/itcastoa"></property> <property name="driverClass" value="com.mysql.jdbc.Driver"></property> <property name="user" value="root"></property> <property name="password" value="966536"></property> <!-- 其他配置 --> <!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 --> <property name="initialPoolSize" value="3"></property> <!--连接池中保留的最小连接数。Default: 3 --> <property name="minPoolSize" value="3"></property> <!--连接池中保留的最大连接数。Default: 15 --> <property name="maxPoolSize" value="5"></property> <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 --> <property name="acquireIncrement" value="3"></property> <!-- 控制数据源内加载的PreparedStatements数量。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 --> <property name="maxStatements" value="8"></property> <!-- maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 --> <property name="maxStatementsPerConnection" value="5"></property> <!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 --> <property name="maxIdleTime" value="1800"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"> </property> </bean> <!-- 配置声明式的事务管理(采用基于注解的方式) --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:annotation-driven transaction-manager="transactionManager"/> </beans> 我的测试代码如下: package cn.itcast.oa.test; import org.hibernate.SessionFactory; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class SpringTest { private ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml"); // 测试SessionFactory @Test public void testSessionFactory() throws Exception { SessionFactory sessionFactory = (SessionFactory) ac.getBean("sessionFactory"); System.out.println(sessionFactory); } // 测试事务 @Test public void testTransaction() throws Exception { TestService testService = (TestService) ac.getBean("testService"); testService.saveTwoUsers(); } }

SSH整合项目,并没有用到日志,但一直报错

# 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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost/xsxk" /> <property name="username" value="root"></property> <property name="password" value="niXIANGZHIDAOma?"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" lazy-init="false"> <!-- 注入datasource,给sessionfactoryBean内setdatasource提供数据源 --> <property name="dataSource" ref="dataSource" /> <property name="hibernateProperties"> <value> <!-- hibernate使用的 方言 --> hibernate.dialect=org.hibernate.dialect.MySQLDialect <!-- 是否打印出sql语句 --> hibernate.show_sql=true </value> </property> <!-- //加载实体类的映射文件位置及名称 --> <property name="mappingResources"> <list> <value>org/model/Glyb.hbm.xml</value> <value>org/model/Dlb.hbm.xml</value> <value>org/model/Jsb.hbm.xml</value> <value>org/model/Kcb.hbm.xml</value> <value>org/model/Xsb.hbm.xml</value> <value>org/model/Zyb.hbm.xml</value> </list> </property> </bean> ``` # web.xml ``` <?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"> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:applicationContext.xml </param-value> </context-param> <filter> <filter-name>openSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>openSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> <init-param> <param-name>actionPackages</param-name> <param-value>org.action</param-value> </init-param> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>login.jsp</welcome-file> </welcome-file-list> </web-app> ``` # 报错 ``` 严重: Exception starting filter struts2 java.lang.StackOverflowError at java.util.concurrent.locks.ReentrantReadWriteLock$Sync.exclusiveCount(Unknown Source) at java.util.concurrent.locks.ReentrantReadWriteLock$Sync.tryAcquireShared(Unknown Source) at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireShared(Unknown Source) at java.util.concurrent.locks.ReentrantReadWriteLock$ReadLock.lock(Unknown Source) at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLoggersInContext(AbstractLoggerAdapter.java:64) at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:47) at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242) at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:39) at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:37) at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:29) at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:52) at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242) at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:39) at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:37) at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:29) at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:52) at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242) at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:39) at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:37) at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:29) at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:52) at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29) ``` # 以上这段错误循环了很多次 ``` java.lang.NoClassDefFoundError: org/apache/logging/log4j/LogManager at org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.<clinit>(StrutsPrepareAndExecuteFilter.java:51) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at java.lang.Class.newInstance(Unknown Source) at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:255) at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397) at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108) at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3693) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4340) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525) 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:117) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) at org.apache.catalina.core.StandardHost.start(StandardHost.java:719) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:516) at org.apache.catalina.core.StandardServer.start(StandardServer.java:710) at org.apache.catalina.startup.Catalina.start(Catalina.java:566) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413) Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.LogManager at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204) ... 33 more ``` # 求各位解答,在线等。

c3p0 连接不释放 请路过的大神过来看看

配置文件如下 <?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:aop="http://www.springframework.org/schema/aop" 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-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <context:annotation-config /> <!-- 打开Spring的Annotation支持 --> <!-- 设定Spring 去哪些包中找Annotation --> <context:component-scan base-package="com.myd" /> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="${driverClass}" /> <property name="jdbcUrl" value="${jdbcUrl}" /> <property name="user" value="${username}" /> <property name="password" value="${password}" /> <!-- 配置连接池的初始值 --> <property name="acquireIncrement" value="${acquireIncrement}" /> <property name="maxPoolSize" value="${maxPoolSize}" /> <property name="minPoolSize" value="${minPoolSize}" /> <property name="initialPoolSize" value="${initialPoolSize}" /> <property name="maxIdleTime" value="${maxIdleTime}" /> <property name="checkoutTimeout" value="${checkoutTimeout}" /> <property name="autoCommitOnClose" value="${autoCommitOnClose}"></property> <property name="acquireRetryDelay" value="${acquireRetryDelay}" /> <property name="idleConnectionTestPeriod" value="${idleConnectionTestPeriod}"></property> <property name="maxStatements" value="${maxStatements}"></property> <property name="numHelperThreads" value="${numHelperThreads}"></property> </bean> <!-- 导入src目录下的c3p0.properties文件 --> <context:property-placeholder location="classpath:c3p0.properties" /> <!--创建Spring的SessionFactory工厂 --> <!-- 如果使用的是Annotation的方式,不能使用LocalSessionFactoryBean,而应该使用 org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <!-- 注入数据源 --> <property name="dataSource" ref="dataSource" /> <!-- 设置Spring取那个包中查找相应的实体类 --> <property name="packagesToScan"> <value>com.myd.entity</value> </property> <property name="hibernateProperties"> <!-- <value> hibernate.dialect=org.hibernate.dialect.HSQLDialect </value> --> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.autoReconnect">true</prop> <prop key="jdbc.use_scrollable_resultset">false</prop> <prop key="hibernate.connection.release_mode">after_statement</prop> <prop key="hibernate.c3p0.validate">true</prop> <prop key="hibernate.c3p0.idle_test_period">30</prop> <prop key="hibernate.c3p0.timeout">30</prop> <prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop> </props> </property> </bean> <!-- 开启HibernateTemplate,并且为其注入SessionFactory 使用HibernateTemplate不太方便的就是要获取session得通过getSessionFactory()方法获取 --> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- 配置Spring的事务处理 --> <!-- 创建事务管理器 --> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- 配置AOP,Spring是通过AOP来进行事务管理的 --> <aop:config> <!-- 设置pointCut表示哪些方法要加入事务处理 --> <!-- 以下的事务是声明在DAO中,但是通常都会在Service来处理多个业务对象逻辑的关系,注入删除,更新等,此时如果在执行了一个步骤之后抛出异常 就会导致数据不完整,所以事务不应该在DAO层处理,而应该在service,这也就是Spring所提供的一个非常方便的工具,声明式事务 --> <aop:pointcut id="allMethods" expression="execution(* com.myd.service.*.*(..))" /> <!-- 通过advisor来确定具体要加入事务控制的方法 --> <aop:advisor advice-ref="txAdvice" pointcut-ref="allMethods" /> </aop:config> <!-- 配置哪些方法要加入事务控制 --> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <!-- 让所有的方法都加入事务管理,为了提高效率,可以把一些查询之类的方法设置为只读的事务 --> <tx:method name="*" propagation="REQUIRED" read-only="true" /> <!-- 以下方法都是可能设计修改的方法,就无法设置为只读 --> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="del*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="save*" propagation="REQUIRED" /> </tx:attributes> </tx:advice> <bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"> <property name="corePoolSize" value="5" /> <property name="maxPoolSize" value="50" /> <property name="queueCapacity" value="1000" /> <property name="keepAliveSeconds" value="60" /> </bean> </beans> 这是事务 package com.myd.dao.impl; import java.lang.reflect.ParameterizedType; import java.sql.SQLException; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; import javax.annotation.Resource; import org.hibernate.HibernateException; import org.hibernate.Query; import org.hibernate.SQLQuery; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.transform.Transformers; import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import org.springframework.stereotype.Repository; import com.myd.dao.BaseDao; /** * 可以考虑把所有公共的方法都写在baseDAo中,让所有的DAO都继承BaseDao * 这样基本上就实现了大量的基础方法,如果DAO中有逻辑处理特殊的方法,再在具体的实现类中的DAO中创建 * * @author Administrator * * @param <T> */ @Repository("baseDaoImpl") public class BaseDaoImpl<T> extends HibernateDaoSupport implements BaseDao<T> { /** * 此处不能使用setSessionFactory注入,因为setSessionFactory在HibernateDaoSupport * 中已经定义了而且还是final的,不能被覆盖 * * @param sessionFactory */ @Resource(name = "sessionFactory") public void setSuperSessionFactory(SessionFactory sessionFactory) { super.setSessionFactory(sessionFactory); } /** * 创建Class的对象来获取泛型的class */ private Class<Object> clz; @SuppressWarnings("unchecked") public Class<Object> getClz() { if (clz == null) { // 获取泛型的Class对象 clz = (Class<Object>) ((ParameterizedType) getClass() .getGenericSuperclass()).getActualTypeArguments()[0]; } return clz; } public void add(T t) { getHibernateTemplate().getSessionFactory().openSession(); getHibernateTemplate().save(t); getHibernateTemplate().getSessionFactory().close(); } public void delete(int id) { getHibernateTemplate().getSessionFactory().openSession(); getHibernateTemplate().delete(load(id)); getHibernateTemplate().getSessionFactory().close(); } @SuppressWarnings("deprecation") public void update(T t) { try { getHibernateTemplate().getSessionFactory().openSession() .connection().prepareStatement("SET SQL_SAFE_UPDATES=0") .execute(); } catch (DataAccessResourceFailureException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (HibernateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } getHibernateTemplate().update(t); getHibernateTemplate().getSessionFactory().close(); } 现在的问题是 运行一段时间后,就卡起, 不是报连接数据库关闭 就是 返回空指针 查了以下是连接未释放导致的,我想请教下各位大神 我这样连接没关闭并回到连接池吗?

struts2.3spring4.1hibernate4.3的集成问题

Error configuring application listener of class org.springframework.web.util.Log4jConfigListener java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener Error configuring application listener of class org.springframework.web.context.ContextLoaderListener java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener Error configuring application listener of class org.springframework.web.context.request.RequestContextListener java.lang.ClassNotFoundException: org.springframework.web.context.request.RequestContextListener spring-web放在WEB-INF/lib下路径是问题的,不知道哪里出错 ``` <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>S2316S411H436</display-name> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>classpath:log4j.properties</param-value> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>struts2Filter</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>hibernate4Filter</filter-name> <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>hibernate4Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app> ``` ``` <?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:p="http://www.springframework.org/schema/p" 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-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"> <!-- 说明:下面有的Bean配置提供了多种方案,请根据需要采用某一种(别忘了注释掉其他同类方案) --> <!-- 自动扫描Spring注解配置 --> <context:component-scan base-package="com" /> <!-- 自动加载属性配置文件 --> <context:property-placeholder location="classpath:jdbc.properties" /> <!-- 配置数据源:方法一,使用C3P0方式(推荐) --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" p:driverClass="${jdbc.driverClassName}" p:jdbcUrl="${jdbc.url}" p:user="${jdbc.username}" p:password="${jdbc.password}" /> <!-- 配置数据源:方法二,使用DBCP方式(不推荐) --> <!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}" p:username="${jdbc.username}" p:password="${jdbc.password}" /> --> <!-- 配置数据源:方法三,使用JNDI方式 --> <!-- <jee:jndi-lookup id="dataSource" jndi-name="${jndi.name}" /> --> <!-- 配置Hibernate的数据源代理工厂:方法一,使用p属性通配符,按文件名搜索匹配的映射文件 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" p:dataSource-ref="dataSource" p:mappingLocations="classpath*:/com/**/*.hbm.xml"> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop> <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop> <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop> </props> </property> </bean> <!-- 配置Hibernate的数据源代理工厂:方法二,使用list集合,按文件名搜索匹配的映射文件 --> <!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" p:dataSource-ref="dataSource"> <property name="mappingLocations"> <list> <value>classpath*:/com/**/*.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop> <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop> <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop> </props> </property> </bean> --> <!-- 配置Hibernate的数据源代理工厂:方法三,使用p属性通配符,按目录搜索映射文件 --> <!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" p:dataSource-ref="dataSource" p:mappingDirectoryLocations="classpath*:/com/**/domain"> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop> <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop> <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop> </props> </property> </bean> --> <!-- 配置Hibernate的数据源代理工厂:方法四,使用hibernate.cfg.xml --> <!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" p:dataSource-ref="dataSource" p:configLocation="classpath:hibernate.cfg.xml"> </bean> --> <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" p:sessionFactory-ref="sessionFactory" /> <!-- 配置声明式事务:方法一,在Service实现类或者public实现方法上使用注解@Transactional,则此类或方法就会启用事务机制 --> <tx:annotation-driven transaction-manager="transactionManager" /> <!-- 配置声明式事务:方法二,使用tx/aop命名空间的配置(其实还有方法三,由于快要过时不推荐使用了,这里就不给出方法三的配置了) --> <!-- <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="edit*" propagation="REQUIRED" /> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="new*" propagation="REQUIRED" /> <tx:method name="set*" propagation="REQUIRED" /> <tx:method name="remove*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="change*" propagation="REQUIRED" /> <tx:method name="get*" propagation="REQUIRED" read-only="true" /> <tx:method name="find*" propagation="REQUIRED" read-only="true" /> <tx:method name="load*" propagation="REQUIRED" read-only="true" /> <tx:method name="search*" propagation="REQUIRED" read-only="true" /> <tx:method name="*" propagation="REQUIRED" read-only="true" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="mypointcut" expression="execution(* com.**.service..*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="mypointcut" /> </aop:config> --> <!-- 下面三个Bean的配置可有可无,但配置后用处更大,通常用于BaseDao类、其他Dao类或特殊工具类中 --> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate" p:sessionFactory-ref="sessionFactory" /> <bean id="hibernateDaoSupport" class="org.springframework.orm.hibernate4.support.HibernateDaoSupport" p:hibernateTemplate-ref="hibernateTemplate" abstract="true"/> <bean id="sessionFactoryUtils" class="org.springframework.orm.hibernate4.SessionFactoryUtils" abstract="true"/> </beans> ```

spring3中的hibernateTemplate怎么拿不到数据

<?xml version="1.0" encoding="UTF-8"?> <!-- 指定Spring配置文件的Schema信息 --> <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:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" default-autowire="byName"> <!-- 加载常量 --> <context:annotation-config /> <context:component-scan base-package="com.demo.oa" /> <!-- 配置数据源 --> <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/hibernate_oa"/> <property name="username" value="root"/> <property name="password" value="taojun"/> <property name="initialSize" value="1"></property> <!--初始化连接池 --> <property name="maxActive" value="50"></property> <!-- 最大连接数 --> <property name="maxIdle" value="20"></property> <!-- 最大空闲连接数 --> <property name="minIdle" value="0"></property> <!-- 最小空闲连接数 --> <property name="maxWait" value="2000"></property> <!-- 连接池耗尽,等待时间2s --> <property name="testOnBorrow" value="true"></property> <!-- 获取连接时,检测是否是有较连接 --> <property name="testOnReturn" value="true"></property> <!-- 归还连接时,检测是否是有较连接 --> <property name="validationQuery" value="select 1"></property> <!-- 配合获取与归还使用 --> <property name="logAbandoned" value="true"></property> <!-- 是否在自动回收超时连接的时候打印连接的超时错误 --> <property name="removeAbandoned" value="true" /> <!--removeAbandoned: 是否自动回收超时连接 --> <property name="removeAbandonedTimeout" value="60" /> <!--removeAbandonedTimeout: 超时时间(以秒数为单位) --> <property name="minEvictableIdleTimeMillis" value="5000"></property> <!--空闲连接最大有效时间 --> <property name="timeBetweenEvictionRunsMillis" value="5000"></property><!-- 每隔5S踢除超时空闲连接 --> </bean> <!--定义了Hibernate的SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <!-- 映射文件采用annotation形式,不用mapping --> <property name="packagesToScan" value="com.demo.oa.model"></property> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.show_sql=true hibernate.format_sql=true hibernate.hbm2ddl.auto=update hibernate.jdbc.batch_size=20 </value> </property> </bean> <!-- <bean id="people" class="com.test.People" /> --> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- more bean definitions go here --> </beans> import java.util.List; import javax.annotation.Resource; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.springframework.orm.hibernate3.HibernateTemplate; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import com.itheima.oa.model.Department; public class DBUtil { private HibernateTemplate hibernateTemplate; public HibernateTemplate getHibernateTemplate() { return hibernateTemplate; } @Resource(name = "hibernateTemplate") public void setHibernateTemplate(HibernateTemplate hibernateTemplate) { this.hibernateTemplate = hibernateTemplate; } public void findDep(){ List li=hibernateTemplate.find("from Department"); System.out.println(li); }

MySQL 8.0.19安装教程(windows 64位)

话不多说直接开干 目录 1-先去官网下载点击的MySQL的下载​ 2-配置初始化的my.ini文件的文件 3-初始化MySQL 4-安装MySQL服务 + 启动MySQL 服务 5-连接MySQL + 修改密码 先去官网下载点击的MySQL的下载 下载完成后解压 解压完是这个样子 配置初始化的my.ini文件的文件 ...

Python+OpenCV计算机视觉

Python+OpenCV计算机视觉系统全面的介绍。

Vue.js 2.0之全家桶系列视频课程

基于新的Vue.js 2.3版本, 目前新全的Vue.js教学视频,让你少走弯路,直达技术前沿! 1. 包含Vue.js全家桶(vue.js、vue-router、axios、vuex、vue-cli、webpack、ElementUI等) 2. 采用笔记+代码案例的形式讲解,通俗易懂

navicat(内含激活码)

navicat支持mysql的可视化操作,内涵激活码,不用再忍受弹框的痛苦。

HTML期末大作业

这是我自己做的HTML期末大作业,花了很多时间,稍加修改就可以作为自己的作业了,而且也可以作为学习参考

150讲轻松搞定Python网络爬虫

【为什么学爬虫?】 &nbsp; &nbsp; &nbsp; &nbsp;1、爬虫入手容易,但是深入较难,如何写出高效率的爬虫,如何写出灵活性高可扩展的爬虫都是一项技术活。另外在爬虫过程中,经常容易遇到被反爬虫,比如字体反爬、IP识别、验证码等,如何层层攻克难点拿到想要的数据,这门课程,你都能学到! &nbsp; &nbsp; &nbsp; &nbsp;2、如果是作为一个其他行业的开发者,比如app开发,web开发,学习爬虫能让你加强对技术的认知,能够开发出更加安全的软件和网站 【课程设计】 一个完整的爬虫程序,无论大小,总体来说可以分成三个步骤,分别是: 网络请求:模拟浏览器的行为从网上抓取数据。 数据解析:将请求下来的数据进行过滤,提取我们想要的数据。 数据存储:将提取到的数据存储到硬盘或者内存中。比如用mysql数据库或者redis等。 那么本课程也是按照这几个步骤循序渐进的进行讲解,带领学生完整的掌握每个步骤的技术。另外,因为爬虫的多样性,在爬取的过程中可能会发生被反爬、效率低下等。因此我们又增加了两个章节用来提高爬虫程序的灵活性,分别是: 爬虫进阶:包括IP代理,多线程爬虫,图形验证码识别、JS加密解密、动态网页爬虫、字体反爬识别等。 Scrapy和分布式爬虫:Scrapy框架、Scrapy-redis组件、分布式爬虫等。 通过爬虫进阶的知识点我们能应付大量的反爬网站,而Scrapy框架作为一个专业的爬虫框架,使用他可以快速提高我们编写爬虫程序的效率和速度。另外如果一台机器不能满足你的需求,我们可以用分布式爬虫让多台机器帮助你快速爬取数据。 &nbsp; 从基础爬虫到商业化应用爬虫,本套课程满足您的所有需求! 【课程服务】 专属付费社群+每周三讨论会+1v1答疑

三个项目玩转深度学习(附1G源码)

从事大数据与人工智能开发与实践约十年,钱老师亲自见证了大数据行业的发展与人工智能的从冷到热。事实证明,计算机技术的发展,算力突破,海量数据,机器人技术等,开启了第四次工业革命的序章。深度学习图像分类一直是人工智能的经典任务,是智慧零售、安防、无人驾驶等机器视觉应用领域的核心技术之一,掌握图像分类技术是机器视觉学习的重中之重。针对现有线上学习的特点与实际需求,我们开发了人工智能案例实战系列课程。打造:以项目案例实践为驱动的课程学习方式,覆盖了智能零售,智慧交通等常见领域,通过基础学习、项目案例实践、社群答疑,三维立体的方式,打造最好的学习效果。

基于STM32的电子时钟设计

时钟功能 还有闹钟功能,温湿度功能,整点报时功能 你值得拥有

学生成绩管理系统(PHP + MYSQL)

做的是数据库课程设计,使用的php + MySQL,本来是黄金搭配也就没啥说的,推荐使用wamp服务器,里面有详细的使用说明,带有界面的啊!呵呵 不行的话,可以给我留言!

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

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

程序员的兼职技能课

获取讲师答疑方式: 在付费视频第一节(触摸命令_ALL)片头有二维码及加群流程介绍 限时福利 原价99元,今日仅需39元!购课添加小助手(微信号:itxy41)按提示还可领取价值800元的编程大礼包! 讲师介绍: 苏奕嘉&nbsp;前阿里UC项目工程师 脚本开发平台官方认证满级(六级)开发者。 我将如何教会你通过【定制脚本】赚到你人生的第一桶金? 零基础程序定制脚本开发课程,是完全针对零脚本开发经验的小白而设计,课程内容共分为3大阶段: ①前期将带你掌握Q开发语言和界面交互开发能力; ②中期通过实战来制作有具体需求的定制脚本; ③后期将解锁脚本的更高阶玩法,打通任督二脉; ④应用定制脚本合法赚取额外收入的完整经验分享,带你通过程序定制脚本开发这项副业,赚取到你的第一桶金!

实用主义学Python(小白也容易上手的Python实用案例)

原价169,限时立减100元! 系统掌握Python核心语法16点,轻松应对工作中80%以上的Python使用场景! 69元=72讲+源码+社群答疑+讲师社群分享会&nbsp; 【哪些人适合学习这门课程?】 1)大学生,平时只学习了Python理论,并未接触Python实战问题; 2)对Python实用技能掌握薄弱的人,自动化、爬虫、数据分析能让你快速提高工作效率; 3)想学习新技术,如:人工智能、机器学习、深度学习等,这门课程是你的必修课程; 4)想修炼更好的编程内功,优秀的工程师肯定不能只会一门语言,Python语言功能强大、使用高效、简单易学。 【超实用技能】 从零开始 自动生成工作周报 职场升级 豆瓣电影数据爬取 实用案例 奥运冠军数据分析 自动化办公:通过Python自动化分析Excel数据并自动操作Word文档,最终获得一份基于Excel表格的数据分析报告。 豆瓣电影爬虫:通过Python自动爬取豆瓣电影信息并将电影图片保存到本地。 奥运会数据分析实战 简介:通过Python分析120年间奥运会的数据,从不同角度入手分析,从而得出一些有趣的结论。 【超人气老师】 二两 中国人工智能协会高级会员 生成对抗神经网络研究者 《深入浅出生成对抗网络:原理剖析与TensorFlow实现》一书作者 阿里云大学云学院导师 前大型游戏公司后端工程师 【超丰富实用案例】 0)图片背景去除案例 1)自动生成工作周报案例 2)豆瓣电影数据爬取案例 3)奥运会数据分析案例 4)自动处理邮件案例 5)github信息爬取/更新提醒案例 6)B站百大UP信息爬取与分析案例 7)构建自己的论文网站案例

Java8零基础入门视频教程

这门课程基于主流的java8平台,由浅入深的详细讲解了java SE的开发技术,可以使java方向的入门学员,快速扎实的掌握java开发技术!

Python数据挖掘简易入门

&nbsp; &nbsp; &nbsp; &nbsp; 本课程为Python数据挖掘方向的入门课程,课程主要以真实数据为基础,详细介绍数据挖掘入门的流程和使用Python实现pandas与numpy在数据挖掘方向的运用,并深入学习如何运用scikit-learn调用常用的数据挖掘算法解决数据挖掘问题,为进一步深入学习数据挖掘打下扎实的基础。

零基础学C#编程—C#从小白到大咖

本课程从初学者角度出发,提供了C#从入门到成为程序开发高手所需要掌握的各方面知识和技术。 【课程特点】 1 由浅入深,编排合理; 2 视频讲解,精彩详尽; 3 丰富实例,轻松易学; 4 每章总结配有难点解析文档。 15大章节,228课时,1756分钟与你一同进步!

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

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

多功能数字钟.zip

利用数字电子计数知识设计并制作的数字电子钟(含multisim仿真),该数字钟具有显示星期、24小时制时间、闹铃、整点报时、时间校准功能

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

想学好JAVA必须要报两万的培训班吗? Java大神勿入 如果你: 零基础想学JAVA却不知道从何入手 看了一堆书和视频却还是连JAVA的环境都搭建不起来 囊中羞涩面对两万起的JAVA培训班不忍直视 在职没有每天大块的时间专门学习JAVA 那么恭喜你找到组织了,在这里有: 1. 一群志同道合立志学好JAVA的同学一起学习讨论JAVA 2. 灵活机动的学习时间完成特定学习任务+每日编程实战练习 3. 热心助人的助教和讲师及时帮你解决问题,不按时完成作业小心助教老师的家访哦 上一张图看看前辈的感悟: &nbsp; &nbsp; 大家一定迫不及待想知道什么是极简JAVA学习营了吧,下面就来给大家说道说道: 什么是极简JAVA学习营? 1. 针对Java小白或者初级Java学习者; 2. 利用9天时间,每天1个小时时间; 3.通过 每日作业 / 组队PK / 助教答疑 / 实战编程 / 项目答辩 / 社群讨论 / 趣味知识抢答等方式让学员爱上学习编程 , 最终实现能独立开发一个基于控制台的‘库存管理系统’ 的学习模式 极简JAVA学习营是怎么学习的? &nbsp; 如何报名? 只要购买了极简JAVA一:JAVA入门就算报名成功! &nbsp;本期为第四期极简JAVA学习营,我们来看看往期学员的学习状态: 作业看这里~ &nbsp; 助教的作业报告是不是很专业 不交作业打屁屁 助教答疑是不是很用心 &nbsp; 有奖抢答大家玩的很嗨啊 &nbsp; &nbsp; 项目答辩终于开始啦 &nbsp; 优秀者的获奖感言 &nbsp; 这是答辩项目的效果 &nbsp; &nbsp; 这么细致的服务,这么好的氛围,这样的学习效果,需要多少钱呢? 不要1999,不要199,不要99,只要9.9 是的你没听错,只要9.9以上所有就都属于你了 如果你: 1、&nbsp;想学JAVA没有基础 2、&nbsp;想学JAVA没有整块的时间 3、&nbsp;想学JAVA没有足够的预算 还等什么?赶紧报名吧,抓紧抢位,本期只招300人,错过只有等时间待定的下一期了 &nbsp; 报名请加小助手微信:eduxy-1 &nbsp; &nbsp;

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

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

Java基础知识面试题(2020最新版)

文章目录Java概述何为编程什么是Javajdk1.5之后的三大版本JVM、JRE和JDK的关系什么是跨平台性?原理是什么Java语言有哪些特点什么是字节码?采用字节码的最大好处是什么什么是Java程序的主类?应用程序和小程序的主类有何不同?Java应用程序与小程序之间有那些差别?Java和C++的区别Oracle JDK 和 OpenJDK 的对比基础语法数据类型Java有哪些数据类型switc...

机器学习实战系列套餐(必备基础+经典算法+案例实战)

机器学习实战系列套餐以实战为出发点,帮助同学们快速掌握机器学习领域必备经典算法原理并结合Python工具包进行实战应用。建议学习顺序:1.Python必备工具包:掌握实战工具 2.机器学习算法与实战应用:数学原理与应用方法都是必备技能 3.数据挖掘实战:通过真实数据集进行项目实战。按照下列课程顺序学习即可! 课程风格通俗易懂,用最接地气的方式带领大家轻松进军机器学习!提供所有课程代码,PPT与实战数据,有任何问题欢迎随时与我讨论。

Java面试题大全(2020版)

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

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

深度学习原理+项目实战+算法详解+主流框架(套餐)

深度学习系列课程从深度学习基础知识点开始讲解一步步进入神经网络的世界再到卷积和递归神经网络,详解各大经典网络架构。实战部分选择当下最火爆深度学习框架PyTorch与Tensorflow/Keras,全程实战演示框架核心使用与建模方法。项目实战部分选择计算机视觉与自然语言处理领域经典项目,从零开始详解算法原理,debug模式逐行代码解读。适合准备就业和转行的同学们加入学习! 建议按照下列课程顺序来进行学习 (1)掌握深度学习必备经典网络架构 (2)深度框架实战方法 (3)计算机视觉与自然语言处理项目实战。(按照课程排列顺序即可)

HoloLens2开发入门教程

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

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

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

MFC一站式终极全套课程包

该套餐共包含从C小白到C++到MFC的全部课程,整套学下来绝对成为一名C++大牛!!!

【数据结构与算法综合实验】欢乐连连看(C++ & MFC)案例

这是武汉理工大学计算机学院数据结构与算法综合实验课程的第三次项目:欢乐连连看(C++ & MFC)迭代开发代码。运行环境:VS2017。已经实现功能:开始游戏、消子、判断胜负、提示、重排、计时、帮助。

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

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

u-boot-2015.07.tar.bz2

uboot-2015-07最新代码,喜欢的朋友请拿去

相关热词 c# 开发接口 c# 中方法上面的限制 c# java 时间戳 c#单元测试入门 c# 数组转化成文本 c#实体类主外键关系设置 c# 子函数 局部 c#窗口位置设置 c# list 查询 c# 事件 执行顺序
立即提问
相关内容推荐