问题描述
在包下写的测试类下写TestHibernate类,用junit测试,能正常进行插入到数据库表中,把表删除后也能自动创建,类如下:packagesy.test;importorg.junit.Test;importorg.springframework.context.ApplicationContext;importorg.springframework.context.support.ClassPathXmlApplicationContext;importsy.model.Tuser;importsy.service.UserServiceI;publicclassTestHibernate{@Testpublicvoidtest(){ApplicationContextac=newClassPathXmlApplicationContext(newString[]{"classpath:spring.xml","classpath:spring-hibernate.xml"});UserServiceIuserService=(UserServiceI)ac.getBean("userService");Tusert=newTuser();t.setId("0014");t.setName("s3114");t.setPwd("123");userService.save(t);}}
最后错误报告TESTS-------------------------------------------------------Runningsy.test.TestHibernate[org.springframework.context.support.ClassPathXmlApplicationContext]Refreshingorg.springframework.context.support.ClassPathXmlApplicationContext@3da99561:startupdate[SatApr1223:46:20CST2014];rootofcontexthierarchy[org.springframework.beans.factory.xml.XmlBeanDefinitionReader]LoadingXMLbeandefinitionsfromclasspathresource[spring.xml][org.springframework.beans.factory.xml.XmlBeanDefinitionReader]LoadingXMLbeandefinitionsfromclasspathresource[spring-hibernate.xml][org.springframework.beans.factory.config.PropertyPlaceholderConfigurer]Loadingpropertiesfilefromclasspathresource[config.properties]中间省略一楼createtableSSHE.TUSER(IDvarchar(36)notnullunique,CREATEDATETIMEdatetime,MODIFYDATETIMEdatetime,NAMEvarchar(100)notnullunique,PWDvarchar(32)notnull,primarykey(ID),unique(NAME))com.alibaba.druid.sql.parser.SQLParseException:syntaxerror,expectRPAREN,actualUNIQUEuniqueatcom.alibaba.druid.sql.parser.SQLParser.accept(SQLParser.java:121)在Tomcat下跑包如下错误一、org.springframework.beans.factory.BeanDefinitionStoreException:IOExceptionparsingXMLdocumentfromServletContextresource[/spring-hibernate.xml];nestedexceptionisjava.io.FileNotFoundException:CouldnotopenServletContextresource[/spring-hibernate.xml]二、严重:Exceptionsendingcontextinitializedeventtolistenerinstanceofclassorg.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanDefinitionStoreException:IOExceptionparsingXMLdocumentfromServletContextresource[/spring-hibernate.xml];nestedexceptionisjava.io.FileNotFoundException:CouldnotopenServletContextresource[/spring-hibernate.xml]三、2014-4-130:26:35org.apache.catalina.core.StandardContextstart严重:ErrorlistenerStart2014-4-130:26:35org.apache.catalina.core.StandardContextstart严重:Context[/sshs]startupfailedduetopreviouserrors2014-4-130:26:35org.apache.catalina.core.ApplicationContextlog信息:ClosingSpringrootWebApplicationContext[org.springframework.web.context.support.XmlWebApplicationContext]ClosingRootWebApplicationContext:startupdate[SunApr1300:26:35CST2014];rootofcontexthierarchy[org.springframework.web.context.support.XmlWebApplicationContext]ExceptionthrownfromApplicationListenerhandlingContextClosedEventjava.lang.IllegalStateException:ApplicationEventMulticasternotinitialized-call'refresh'beforemulticastingeventsviathecontext:RootWebApplicationContext:startupdate[SunApr1300:26:35CST2014];rootofcontexthierarchy这个是我的目录结构UserAction类:packagesy.action;importjava.util.Date;importjava.util.UUID;importorg.apache.log4j.Logger;importorg.apache.struts2.convention.annotation.Action;importorg.apache.struts2.convention.annotation.Namespace;importorg.apache.struts2.convention.annotation.ParentPackage;importorg.springframework.beans.factory.annotation.Autowired;importsy.model.Tuser;importsy.service.UserServiceI;@ParentPackage("basePackage")@Namespace("/")@Action(value="userAction")publicclassUserAction{privatestaticfinalLoggerlogger=Logger.getLogger(UserAction.class);privateUserServiceIuserService;publicUserServiceIgetUserService(){returnuserService;}@AutowiredpublicvoidsetUserService(UserServiceIuserService){this.userService=userService;}publicvoidtest(){logger.info("进入Action");userService.test();}//publicvoidaddUser(){//Tusert=newTuser();//t.setId(UUID.randomUUID().toString());//t.setName("tt");//t.setPwd("343");//t.setCreatedatetime(newDate());//userService.save(t);//}}
sy.dao.impl的UserDaoImpl类packagesy.dao.impl;importjava.io.Serializable;importorg.hibernate.SessionFactory;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.stereotype.Repository;importsy.dao.UserDaoI;importsy.model.Tuser;@Repository("userDao")publicclassUserDaoImplimplementsUserDaoI{privateSessionFactorysessionFactory;publicSessionFactorygetSessionFactory(){returnsessionFactory;}@AutowiredpublicvoidsetSessionFactory(SessionFactorysessionFactory){this.sessionFactory=sessionFactory;}@OverridepublicSerializablesave(Tusert){returnthis.sessionFactory.getCurrentSession().save(t);}}
sy.dao包下的UserDaoI类packagesy.dao;importjava.io.Serializable;importsy.model.Tuser;publicinterfaceUserDaoI{publicSerializablesave(Tusert);}
sy.model的Tuser类packagesy.model;importjava.util.Date;importjavax.persistence.Column;importjavax.persistence.Entity;importjavax.persistence.Id;importjavax.persistence.Table;importjavax.persistence.Temporal;importjavax.persistence.TemporalType;importjavax.persistence.UniqueConstraint;/***Tuserentity.@authorMyEclipsePersistenceTools*/@Entity@Table(name="TUSER",schema="SSHE",uniqueConstraints=@UniqueConstraint(columnNames="NAME"))publicclassTuserimplementsjava.io.Serializable{//FieldsprivateStringid;privateStringname;privateStringpwd;privateDatecreatedatetime;privateDatemodifydatetime;//Constructors/**defaultconstructor*/publicTuser(){}/**minimalconstructor*/publicTuser(Stringid,Stringname,Stringpwd){this.id=id;this.name=name;this.pwd=pwd;}/**fullconstructor*/publicTuser(Stringid,Stringname,Stringpwd,Datecreatedatetime,Datemodifydatetime){this.id=id;this.name=name;this.pwd=pwd;this.createdatetime=createdatetime;this.modifydatetime=modifydatetime;}//Propertyaccessors@Id@Column(name="ID",unique=true,nullable=false,length=36)publicStringgetId(){returnthis.id;}publicvoidsetId(Stringid){this.id=id;}@Column(name="NAME",unique=true,nullable=false,length=100)publicStringgetName(){returnthis.name;}publicvoidsetName(Stringname){this.name=name;}@Column(name="PWD",nullable=false,length=32)publicStringgetPwd(){returnthis.pwd;}publicvoidsetPwd(Stringpwd){this.pwd=pwd;}@Temporal(TemporalType.TIMESTAMP)@Column(name="CREATEDATETIME",length=7)publicDategetCreatedatetime(){returnthis.createdatetime;}publicvoidsetCreatedatetime(Datecreatedatetime){this.createdatetime=createdatetime;}@Temporal(TemporalType.TIMESTAMP)@Column(name="MODIFYDATETIME",length=7)publicDategetModifydatetime(){returnthis.modifydatetime;}publicvoidsetModifydatetime(Datemodifydatetime){this.modifydatetime=modifydatetime;}}
sy.service.impl的UserServiceImpl类packagesy.service.impl;importjava.io.Serializable;importorg.apache.log4j.Logger;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.stereotype.Service;importsy.dao.UserDaoI;importsy.model.Tuser;importsy.service.UserServiceI;@Service(value="userService")publicclassUserServiceImplimplementsUserServiceI{privatestaticfinalLoggerlogger=Logger.getLogger(UserServiceImpl.class);privateUserDaoIuserDao;publicUserDaoIgetUserDao(){returnuserDao;}@AutowiredpublicvoidsetUserDao(UserDaoIuserDao){this.userDao=userDao;}@Overridepublicvoidtest(){logger.info("wwww");}@OverridepublicSerializablesave(Tusert){returnuserDao.save(t);}}
sy.service的UserServiceIpackagesy.service;importjava.io.Serializable;importsy.model.Tuser;publicinterfaceUserServiceI{publicvoidtest();publicSerializablesave(Tusert);}
man/resources下的几个配置文件config.propertieshibernate.dialect=org.hibernate.dialect.MySQLDialectdriverClassName=com.mysql.jdbc.DrivervalidationQuery=SELECT1jdbc_url=jdbc:mysql://localhost:3306/sy?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNulljdbc_username=rootjdbc_password=123#jndiName=java:comp/env/dataSourceNamehibernate.hbm2ddl.auto=updatehibernate.show_sql=truehibernate.format_sql=truesessionInfoName=sessionInfouploadFieldName=filedatauploadFileMaxSize=20971520uploadFileExts=txt,rar,zip,doc,docx,xls,xlsx,jpg,jpeg,gif,png,swf,wmv,avi,wma,mp3,miduploadDirectory=attachedman/resources下的几个配置文件log4j.propertieslog4j.rootLogger=INFO,A1,Rlog4j.appender.A1=org.apache.log4j.ConsoleAppenderlog4j.appender.A1.Target=System.outlog4j.appender.A1.layout=org.apache.log4j.PatternLayoutlog4j.appender.A1.layout.ConversionPattern=[%c]%m%nlog4j.appender.R=org.apache.log4j.RollingFileAppenderlog4j.appender.R.File=sshe.loglog4j.appender.R.MaxFileSize=10MBlog4j.appender.R.Threshold=ALLlog4j.appender.R.layout=org.apache.log4j.PatternLayoutlog4j.appender.R.layout.ConversionPattern=[%p][%d{yyyy-MM-ddHH:mm:ss,SSS}][%c]%m%n
解决方案
本帖最后由 MengXiangXuYaoNuLi 于 2014-04-13 00:29:46 编辑
解决方案二:
java.sql.DatabaseMetaData]HHH000262:Tablenotfound:TUSER[java.sql.DatabaseMetaData]HHH000262:Tablenotfound:TUSER[com.alibaba.druid.filter.stat.StatFilter]mergesqlerror,dbTypemysql,sql:createtableSSHE.TUSER(IDvarchar(36)notnullunique,CREATEDATETIMEdatetime,MODIFYDATETIMEdatetime,NAMEvarchar(100)notnullunique,PWDvarchar(32)notnull,primarykey(ID),unique(NAME))com.alibaba.druid.sql.parser.SQLParseException:syntaxerror,expectRPAREN,actualUNIQUEuniqueatcom.alibaba.druid.sql.parser.SQLParser.accept(SQLParser.java:121)atcom.alibaba.druid.sql.dialect.mysql.parser.MySqlCreateTableParser.parseCrateTable(MySqlCreateTableParser.java:121)atcom.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser.parseCreate(MySqlStatementParser.java:304)atcom.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:94)atcom.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:68)atcom.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils.parameterize(ParameterizedOutputVisitorUtils.java:40)atcom.alibaba.druid.filter.stat.StatFilter.mergeSql(StatFilter.java:145)atcom.alibaba.druid.filter.stat.StatFilter.createSqlStat(StatFilter.java:647)atcom.alibaba.druid.filter.stat.StatFilter.internalBeforeStatementExecute(StatFilter.java:402)atcom.alibaba.druid.filter.stat.StatFilter.statementExecuteUpdateBefore(StatFilter.java:325)atcom.alibaba.druid.filter.FilterEventAdapter.statement_executeUpdate(FilterEventAdapter.java:324)atcom.alibaba.druid.filter.FilterChainImpl.statement_executeUpdate(FilterChainImpl.java:2369)atcom.alibaba.druid.proxy.jdbc.StatementProxyImpl.executeUpdate(StatementProxyImpl.java:169)atcom.alibaba.druid.pool.DruidPooledStatement.executeUpdate(DruidPooledStatement.java:135)atorg.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:227)atorg.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:178)atorg.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:492)atorg.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750)atorg.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1788)atorg.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:242)atorg.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:372)atorg.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:357)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:876)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:818)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:735)atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:551)atorg.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)atorg.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)atorg.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)atsy.test.TestHibernate.test(TestHibernate.java:16)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:597)atorg.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)atorg.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)atorg.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)atorg.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)atorg.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)atorg.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)atorg.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)atorg.junit.runners.ParentRunner$3.run(ParentRunner.java:238)atorg.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)atorg.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)atorg.junit.runners.ParentRunner.access$000(ParentRunner.java:53)atorg.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)atorg.junit.runners.ParentRunner.run(ParentRunner.java:309)atorg.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)atorg.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)[org.hibernate.tool.hbm2ddl.SchemaUpdate]HHH000388:Unsuccessful:createtableSSHE.TUSER(IDvarchar(36)notnullunique,CREATEDATETIMEdatetime,MODIFYDATETIMEdatetime,NAMEvarchar(100)notnullunique,PWDvarchar(32)notnull,primarykey(ID),unique(NAME))[org.hibernate.tool.hbm2ddl.SchemaUpdate]Table'tuser'alreadyexists[org.hibernate.tool.hbm2ddl.SchemaUpdate]HHH000232:Schemaupdatecomplete[org.springframework.orm.hibernate4.HibernateTransactionManager]UsingDataSource[{CreateTime:"2014-04-1300:31:41",ActiveCount:0,PoolingCount:1,CreateCount:1,DestroyCount:0,CloseCount:2,ConnectCount:2,Connections:[{ID:608447606,ConnectTime:"2014-04-1300:31:43",UseCount:2,LastActiveTime:"2014-04-1300:31:44"}]}]ofHibernateSessionFactoryforHibernateTransactionManagerHibernate:insertintoSSHE.TUSER(CREATEDATETIME,MODIFYDATETIME,NAME,PWD,ID)values(?,?,?,?,?)[org.hibernate.engine.jdbc.spi.SqlExceptionHelper]SQLError:1062,SQLState:23000[org.hibernate.engine.jdbc.spi.SqlExceptionHelper]Duplicateentry'0014'forkey1[org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl]HHH000010:OnreleaseofbatchitstillcontainedJDBCstatements
解决方案三:
spring-hibernate.xml的配置文件<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="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"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.0.xsd"><!--JNDI方式配置数据源--><!--<beanid="dataSource"class="org.springframework.jndi.JndiObjectFactoryBean"><propertyname="jndiName"value="${jndiName}"></property></bean>--><!--配置数据源--><beanname="dataSource"class="com.alibaba.druid.pool.DruidDataSource"init-method="init"destroy-method="close"><propertyname="url"value="${jdbc_url}"/><propertyname="username"value="${jdbc_username}"/><propertyname="password"value="${jdbc_password}"/><!--初始化连接大小--><propertyname="initialSize"value="0"/><!--连接池最大使用连接数量--><propertyname="maxActive"value="20"/><!--连接池最大空闲--><propertyname="maxIdle"value="20"/><!--连接池最小空闲--><propertyname="minIdle"value="0"/><!--获取连接最大等待时间--><propertyname="maxWait"value="60000"/><!--<propertyname="poolPreparedStatements"value="true"/><propertyname="maxPoolPreparedStatementPerConnectionSize"value="33"/>--><propertyname="validationQuery"value="${validationQuery}"/><propertyname="testOnBorrow"value="false"/><propertyname="testOnReturn"value="false"/><propertyname="testWhileIdle"value="true"/><!--配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒--><propertyname="timeBetweenEvictionRunsMillis"value="60000"/><!--配置一个连接在池中最小生存的时间,单位是毫秒--><propertyname="minEvictableIdleTimeMillis"value="25200000"/><!--打开removeAbandoned功能--><propertyname="removeAbandoned"value="true"/><!--1800秒,也就是30分钟--><propertyname="removeAbandonedTimeout"value="1800"/><!--关闭abanded连接时输出错误日志--><propertyname="logAbandoned"value="true"/><!--监控数据库--><!--<propertyname="filters"value="stat"/>--><propertyname="filters"value="mergeStat"/></bean><!--配置hibernatesession工厂--><beanid="sessionFactory"class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"><propertyname="dataSource"ref="dataSource"/><propertyname="hibernateProperties"><props><propkey="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop><propkey="hibernate.dialect">${hibernate.dialect}</prop><propkey="hibernate.show_sql">${hibernate.show_sql}</prop><propkey="hibernate.format_sql">${hibernate.format_sql}</prop></props></property><!--自动扫描注解方式配置的hibernate类文件--><propertyname="packagesToScan"><list><value>sy.model</value></list></property><!--自动扫描hbm方式配置的hibernate文件和.hbm文件--><!--<propertyname="mappingDirectoryLocations"><list><value>classpath:sy/hbm</value></list></property>--></bean><!--配置事务管理器--><beanname="transactionManager"class="org.springframework.orm.hibernate4.HibernateTransactionManager"><propertyname="sessionFactory"ref="sessionFactory"></property></bean><!--注解方式配置事物--><!--<tx:annotation-driventransaction-manager="transactionManager"/>--><!--拦截器方式配置事物--><tx:adviceid="transactionAdvice"transaction-manager="transactionManager"><tx:attributes><tx:methodname="add*"/><tx:methodname="save*"/><tx:methodname="update*"/><tx:methodname="modify*"/><tx:methodname="edit*"/><tx:methodname="delete*"/><tx:methodname="remove*"/><tx:methodname="repair"/><tx:methodname="deleteAndRepair"/><tx:methodname="get*"propagation="SUPPORTS"/><tx:methodname="find*"propagation="SUPPORTS"/><tx:methodname="load*"propagation="SUPPORTS"/><tx:methodname="search*"propagation="SUPPORTS"/><tx:methodname="datagrid*"propagation="SUPPORTS"/><tx:methodname="*"propagation="SUPPORTS"/></tx:attributes></tx:advice><aop:config><aop:pointcutid="transactionPointcut"expression="execution(*sy.service..*Impl.*(..))"/><aop:advisorpointcut-ref="transactionPointcut"advice-ref="transactionAdvice"/></aop:config></beans>
解决方案四:
spring.xml文件<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd"><!--引入属性文件--><context:property-placeholderlocation="classpath:config.properties"/><!--自动扫描dao和service包(自动注入)--><context:component-scanbase-package="sy.dao,sy.service"/></beans>
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEstrutsPUBLIC"-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"><struts><!--指定由spring负责action对象的创建--><constantname="struts.objectFactory"value="spring"/><!--所有匹配*.action的请求都由struts2处理--><constantname="struts.action.extension"value="action"/><!--是否启用开发模式--><constantname="struts.devMode"value="true"/><!--struts配置文件改动后,是否重新加载--><constantname="struts.configuration.xml.reload"value="true"/><!--设置浏览器是否缓存静态内容--><constantname="struts.serve.static.browserCache"value="false"/><!--请求参数的编码方式--><constantname="struts.i18n.encoding"value="utf-8"/><!--每次HTTP请求系统都重新加载资源文件,有助于开发--><constantname="struts.i18n.reload"value="true"/><!--文件上传最大值--><constantname="struts.multipart.maxSize"value="104857600"/><!--让struts2支持动态方法调用--><constantname="struts.enable.DynamicMethodInvocation"value="true"/><!--Action名称中是否还是用斜线--><constantname="struts.enable.SlashesInActionNames"value="false"/><!--允许标签中使用表达式语法--><constantname="struts.tag.altSyntax"value="true"/><!--对于WebLogic,Orion,OC4J此属性应该设置成true--><constantname="struts.dispatcher.parametersWorkaround"value="false"/><packagename="basePackage"extends="struts-default"></package></struts>
解决方案五:
好长哦spring-hibernate.xml没有找着呢,看看关于它的路径设置对不对
解决方案六:
应该是对的吧,我也的是自动扫描<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="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"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.0.xsd"><!--JNDI方式配置数据源--><!--<beanid="dataSource"class="org.springframework.jndi.JndiObjectFactoryBean"><propertyname="jndiName"value="${jndiName}"></property></bean>--><!--配置数据源--><beanname="dataSource"class="com.alibaba.druid.pool.DruidDataSource"init-method="init"destroy-method="close"><propertyname="url"value="${jdbc_url}"/><propertyname="username"value="${jdbc_username}"/><propertyname="password"value="${jdbc_password}"/><!--初始化连接大小--><propertyname="initialSize"value="0"/><!--连接池最大使用连接数量--><propertyname="maxActive"value="20"/><!--连接池最大空闲--><propertyname="maxIdle"value="20"/><!--连接池最小空闲--><propertyname="minIdle"value="0"/><!--获取连接最大等待时间--><propertyname="maxWait"value="60000"/><!--<propertyname="poolPreparedStatements"value="true"/><propertyname="maxPoolPreparedStatementPerConnectionSize"value="33"/>--><propertyname="validationQuery"value="${validationQuery}"/><propertyname="testOnBorrow"value="false"/><propertyname="testOnReturn"value="false"/><propertyname="testWhileIdle"value="true"/><!--配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒--><propertyname="timeBetweenEvictionRunsMillis"value="60000"/><!--配置一个连接在池中最小生存的时间,单位是毫秒--><propertyname="minEvictableIdleTimeMillis"value="25200000"/><!--打开removeAbandoned功能--><propertyname="removeAbandoned"value="true"/><!--1800秒,也就是30分钟--><propertyname="removeAbandonedTimeout"value="1800"/><!--关闭abanded连接时输出错误日志--><propertyname="logAbandoned"value="true"/><!--监控数据库--><!--<propertyname="filters"value="stat"/>--><propertyname="filters"value="mergeStat"/></bean><!--配置hibernatesession工厂--><beanid="sessionFactory"class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"><propertyname="dataSource"ref="dataSource"/><propertyname="hibernateProperties"><props><propkey="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop><propkey="hibernate.dialect">${hibernate.dialect}</prop><propkey="hibernate.show_sql">${hibernate.show_sql}</prop><propkey="hibernate.format_sql">${hibernate.format_sql}</prop></props></property><!--自动扫描注解方式配置的hibernate类文件--><propertyname="packagesToScan"><list><value>sy.model</value></list></property><!--自动扫描hbm方式配置的hibernate文件和.hbm文件--><!--<propertyname="mappingDirectoryLocations"><list><value>classpath:sy/hbm</value></list></property>--></bean><!--配置事务管理器--><beanname="transactionManager"class="org.springframework.orm.hibernate4.HibernateTransactionManager"><propertyname="sessionFactory"ref="sessionFactory"></property></bean><!--注解方式配置事物--><!--<tx:annotation-driventransaction-manager="transactionManager"/>--><!--拦截器方式配置事物--><tx:adviceid="transactionAdvice"transaction-manager="transactionManager"><tx:attributes><tx:methodname="add*"/><tx:methodname="save*"/><tx:methodname="update*"/><tx:methodname="modify*"/><tx:methodname="edit*"/><tx:methodname="delete*"/><tx:methodname="remove*"/><tx:methodname="repair"/><tx:methodname="deleteAndRepair"/><tx:methodname="get*"propagation="SUPPORTS"/><tx:methodname="find*"propagation="SUPPORTS"/><tx:methodname="load*"propagation="SUPPORTS"/><tx:methodname="search*"propagation="SUPPORTS"/><tx:methodname="datagrid*"propagation="SUPPORTS"/><tx:methodname="*"propagation="SUPPORTS"/></tx:attributes></tx:advice><aop:config><aop:pointcutid="transactionPointcut"expression="execution(*sy.service..*Impl.*(..))"/><aop:advisorpointcut-ref="transactionPointcut"advice-ref="transactionAdvice"/></aop:config></beans>
解决方案七:
引用4楼defonds的回复:
好长哦spring-hibernate.xml没有找着呢,看看关于它的路径设置对不对
我怀疑是不是我的Tuser类是不是错了?
解决方案八:
重新install就好了,
解决方案九:
com.alibaba.druid.filter.stat.StatFilter]mergesqlerror,dbTypemysql,sql:createtableSSHE.TMENU(IDvarchar(36)notnullunique,ICONCLSvarchar(50),TEXTvarchar(100),URLvarchar(200),PIDvarchar(36),primarykey(ID))com.alibaba.druid.sql.parser.SQLParseException:syntaxerror,expectRPAREN,actualUNIQUEuniqueatcom.alibaba.druid.sql.parser.SQLParser.accept(SQLParser.java:121)atcom.alibaba.druid.sql.dialect.mysql.parser.MySqlCreateTableParser.parseCrateTable(MySqlCreateTableParser.java:121)atcom.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser.parseCreate(MySqlStatementParser.java:304)atcom.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:94)atcom.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:68)atcom.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils.parameterize(ParameterizedOutputVisitorUtils.java:40)atcom.alibaba.druid.filter.stat.StatFilter.mergeSql(StatFilter.java:145)atcom.alibaba.druid.filter.stat.StatFilter.createSqlStat(StatFilter.java:647)atcom.alibaba.druid.filter.stat.StatFilter.internalBeforeStatementExecute(StatFilter.java:402)atcom.alibaba.druid.filter.stat.StatFilter.statementExecuteUpdateBefore(StatFilter.java:325)atcom.alibaba.druid.filter.FilterEventAdapter.statement_executeUpdate(FilterEventAdapter.java:324)atcom.alibaba.druid.filter.FilterChainImpl.statement_executeUpdate(FilterChainImpl.java:2369)atcom.alibaba.druid.proxy.jdbc.StatementProxyImpl.executeUpdate(StatementProxyImpl.java:169)atcom.alibaba.druid.pool.DruidPooledStatement.executeUpdate(DruidPooledStatement.java:135)atorg.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:227)atorg.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:178)atorg.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:492)atorg.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750)atorg.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1788)atorg.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:242)atorg.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:372)atorg.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:357)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:876)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:818)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:735)atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:551)atorg.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)atorg.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)atorg.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)atorg.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)atorg.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)atorg.apache.catalina.core.StandardContext.start(StandardContext.java:4705)atorg.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)atorg.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)atorg.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)atorg.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)atorg.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)atorg.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)atorg.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)atorg.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)atorg.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)atorg.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)atorg.apache.catalina.core.StandardHost.start(StandardHost.java:840)atorg.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)atorg.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)atorg.apache.catalina.core.StandardService.start(StandardService.java:525)atorg.apache.catalina.core.StandardServer.start(StandardServer.java:754)atorg.apache.catalina.startup.Catalina.start(Catalina.java:595)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:597)atorg.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)atorg.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
解决方案十:
//Propertyaccessors@Id@Column(name="ID",unique=true,nullable=false,length=36)publicStringgetId(){returnthis.id;}去掉unique=true属性就不报错了啊