[计算机]Myeclipse 701建立SpringHibernate项目步骤图解.doc
淘宝网女装冬装 本文由淘宝网女装冬装 整理提供。Myeclipse 7.01建立Spring+Hibernate项目步骤图解1, 建立一个dynamic web项目2, 填入project name,选择target runtime(如果不存在请先new一个)3, 添加spring特性 3.1 右键点选demo项目,myeclipse->add spring capabilities 3.2 选spring 2.5,然后选择适当的包,这里选择AOP,Core,Persistence Core,Persistence JDBC,Testing Support,Web libraries;然后选择下面的copy checked library contents to project folder,选WEB-INF下的lib文件夹,Tag library installation选WEB-INF文件夹 3.3 Next之后,选择applicationContext.xml配置文件位置为WEB-INF目录,然后点finish,spring capabilities添加结束4, 添加hibernate特性 4.1 准备工作,配置数据源 选菜单栏的window->show view->DBBroswer(如果看不到请到others中找),然后在DB页面右键->new,在弹出的框框中填入数据库驱动,连接字符串等信息,点finish,先放一边 4.2 右键选demo项目,myeclipse->add hibernate capabilities 4.3 把library都选上,如果需要注解支持的话要勾选Enable Hibernate Annotations Support,同样选copy checked library contents to project folder,然后选WEB-INF下的lib目录next 4.4 我们选Spring configuration file,意思是hibernate不用独立的配置文件,和spring共用一个next 4.5 选existing Spring configuration file,然后找到applicaiontContext.xml,因为这里同时还会建立SessionFactory,所以要填入SessionFactory的ID,可以随意,一般用sessionFactory即可(小写s)next 4.6 配置DataSource,首先填入一个DataSourceID,随意,我们填入dataSource,然后在dbDriver那里选择我们刚建立好的数据源next 4.7 是否建立SessionFactoryClass类,可有可无,按要求选择即可 4.8 完成,如果提示某些library已经存在,那么保持已有的即可5, 进一步配置 5.1 添加log4j配置文件 在src目录下建立一个log4j.properties文件,文件内容如下:# This is the configuring for logging displayed in the Application Serverlog4j.rootCategory=INFO, stdout, logfile#stdout configurelog4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern= %d %p %c - <%m>%n#logfile configurelog4j.appender.logfile=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.logfile.File=./logs/extreme-web.loglog4j.appender.logfile.layout=org.apache.log4j.PatternLayoutlog4j.appender.logfile.layout.ConversionPattern= %d %p %c - <%m>%n# Changing the log level to DEBUG when debuglog4j.logger.org.springside.extremeweb=DEBUG# Control logging for other open source packageslog4j.logger.org.springframework=WARN 5.2 修改web.xml配置文件,添加如下节点<!- 指定spring配置文件位置 -><context-param><description>spring config file</description><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/applicationContext*.xml</param-value></context-param><!-Spring ApplicationContext 载入 -><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!- Spring 刷新Introspector防止内存泄露 -><listener><listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class></listener>6, 配置完成,测试加载spring和hibernate6.1 window->show view->Servers右键选择相应server->Add and remove projects,把项目添加到右边,finish6.2 右键->启动server如果看到类似如下信息,那说明配置成功2008-9-15 19:58:24 org.apache.catalina.core.AprLifecycleListener init省略一堆tomcat信息信息: Initializing Spring root WebApplicationContext2008-09-15 19:58:30,062 INFO org.hibernate.cfg.annotations.Version - <Hibernate Annotations 3.3.0.GA>2008-09-15 19:58:30,250 INFO org.hibernate.cfg.Environment - <Hibernate 3.2.5>2008-09-15 19:58:30,265 INFO org.hibernate.cfg.Environment - <hibernate.properties not found>2008-09-15 19:58:30,281 INFO org.hibernate.cfg.Environment - <Bytecode provider name : cglib>2008-09-15 19:58:30,296 INFO org.hibernate.cfg.Environment - <using JDK 1.4 java.sql.Timestamp handling>2008-09-15 19:58:30,843 INFO org.hibernate.connection.ConnectionProviderFactory - <Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider>2008-09-15 19:58:31,578 INFO org.hibernate.cfg.SettingsFactory - <RDBMS: MySQL, version: 5.0.19-nt>2008-09-15 19:58:31,578 INFO org.hibernate.cfg.SettingsFactory - <JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.0.8 ( Revision: $svn.Revision )>2008-09-15 19:58:31,687 INFO org.hibernate.dialect.Dialect - <Using dialect: org.hibernate.dialect.MySQLDialect>2008-09-15 19:58:31,859 INFO org.hibernate.transaction.TransactionFactoryFactory - <Transaction strategy: org.springframework.orm.hibernate3.SpringTransactionFactory>2008-09-15 19:58:31,859 INFO org.hibernate.transaction.TransactionManagerLookupFactory - <No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)>2008-09-15 19:58:31,859 INFO org.hibernate.cfg.SettingsFactory - <Automatic flush during beforeCompletion(): disabled>2008-09-15 19:58:31,859 INFO org.hibernate.cfg.SettingsFactory - <Automatic session close at end of transaction: disabled>2008-09-15 19:58:31,859 INFO org.hibernate.cfg.SettingsFactory - <JDBC batch size: 15>2008-09-15 19:58:31,875 INFO org.hibernate.cfg.SettingsFactory - <JDBC batch updates for versioned data: disabled>2008-09-15 19:58:31,875 INFO org.hibernate.cfg.SettingsFactory - <Scrollable result sets: enabled>2008-09-15 19:58:31,875 INFO org.hibernate.cfg.SettingsFactory - <JDBC3 getGeneratedKeys(): enabled>2008-09-15 19:58:31,875 INFO org.hibernate.cfg.SettingsFactory - <Connection release mode: auto>2008-09-15 19:58:31,875 INFO org.hibernate.cfg.SettingsFactory - <Maximum outer join fetch depth: 2>2008-09-15 19:58:31,875 INFO org.hibernate.cfg.SettingsFactory - <Default batch fetch size: 1>2008-09-15 19:58:31,875 INFO org.hibernate.cfg.SettingsFactory - <Generate SQL with comments: disabled>2008-09-15 19:58:31,875 INFO org.hibernate.cfg.SettingsFactory - <Order SQL updates by primary key: disabled>2008-09-15 19:58:31,875 INFO org.hibernate.cfg.SettingsFactory - <Order SQL inserts for batching: disabled>2008-09-15 19:58:31,875 INFO org.hibernate.cfg.SettingsFactory - <Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory>2008-09-15 19:58:31,890 INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - <Using ASTQueryTranslatorFactory>2008-09-15 19:58:31,890 INFO org.hibernate.cfg.SettingsFactory - <Query language substitutions: >2008-09-15 19:58:31,890 INFO org.hibernate.cfg.SettingsFactory - <JPA-QL strict compliance: disabled>2008-09-15 19:58:31,890 INFO org.hibernate.cfg.SettingsFactory - <Second-level cache: enabled>2008-09-15 19:58:31,890 INFO org.hibernate.cfg.SettingsFactory - <Query cache: disabled>2008-09-15 19:58:31,890 INFO org.hibernate.cfg.SettingsFactory - <Cache provider: org.hibernate.cache.NoCacheProvider>2008-09-15 19:58:31,890 INFO org.hibernate.cfg.SettingsFactory - <Optimize cache for minimal puts: disabled>2008-09-15 19:58:31,890 INFO org.hibernate.cfg.SettingsFactory - <Structured second-level cache entries: disabled>2008-09-15 19:58:31,921 INFO org.hibernate.cfg.SettingsFactory - <Statistics: disabled>2008-09-15 19:58:31,921 INFO org.hibernate.cfg.SettingsFactory - <Deleted entity synthetic identifier rollback: disabled>2008-09-15 19:58:31,937 INFO org.hibernate.cfg.SettingsFactory - <Default entity-mode: pojo>2008-09-15 19:58:31,937 INFO org.hibernate.cfg.SettingsFactory - <Named query checking : enabled>2008-09-15 19:58:32,031 INFO org.hibernate.impl.SessionFactoryImpl - <building session factory>2008-09-15 19:58:32,062 INFO org.hibernate.impl.SessionFactoryObjectFactory - <Not binding factory to JNDI, no JNDI name configured>2008-9-15 19:58:32 org.apache.coyote.http11.Http11Protocol start信息: Starting Coyote HTTP/1.1 on http-80802008-9-15 19:58:32 mon.ChannelSocket init信息: JK: ajp13 listening on /0.0.0.0:80092008-9-15 19:58:32 org.apache.jk.server.JkMain start信息: Jk running ID=0 time=0/110 config=null2008-9-15 19:58:32 org.apache.catalina.startup.Catalina start信息: Server startup in 7488 ms7. 利用hibernate逆向工程生成实体对象 7.1 window->show view->DB Browser, 打开数据库连接,展开树,找到到数据表,选择对应的表(按Ctrl可多选),右键->hibernate reverse engineering,next 7.2 src folder选对应的package位置,然后勾选create pojo,下面有产生配置文件或者注解选项,按需求选即可,这里选配置文件next 7.3 其它的保持默认,Type Mapping 选Hibernate types,如果选择Java Types,那么基本类型比如int,long则会被映射成相应的java对象Integer, Long; 如果选Hibernate types,那么实体对象中用的将会是基本类型int,long ;下面一个是Id generator,即主键生成方式,按实际情况选,各种方式的意思可参考hibernate手册,当然这里也可以不选,用默认的,next 7.4 全部保持默认,完成 7.5 查看相应目录可看到对应的*.hbm.xml文件,如果选的是注解,那这里就可以直接看到实体对象了(以下步骤跳过) 7.6 按CTRL把所有的hbm.xml文件选中,右键myeclipse->generate POJOs,保持默认,finish 7.7 可以看到实体对象自动生成<END>淘宝网女装冬装收集热卖淘宝女装,淘宝网女装秋装,淘宝网女装冬装,同时提供大量的淘宝女装信息,帮助淘友们选择淘宝女装和最新的淘宝女装信息。