求助:最近弄了一个SSH的登录的项目,想请教一下,在SSH下能过在xml中配置,通过运行自动创建表吗?,谢谢想问一下,以下的配置,没有hibernate.cfg.xml配置文件,tomcat在什么情况自动创建表?
并且在web.xml中没有写:
  <context-param>   
  <param-name>contextConfigLocation</param-name>   
  <param-value>/WEB-INF/applicationContext.xml</param-value>   
  </context-param>   
  <servlet>   
      <servlet-name>SpringContextServlet</servlet-name>   
      <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>       
      <load-on-startup>1</load-on-startup>   
  </servlet>
自己写了也不好用.以下是SSH的配置:
struts-config.xml:
        <controller>
   <set-property property="processorClass"
value="org.springframework.web.struts.DelegatingRequestProcessor" />
</controller>
<message-resources parameter="org.tie.struts.ApplicationResources" />
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
        <set-property property="contextConfigLocation" 
                      value="/WEB-INF/applicationContext.xml" />
</plug-in>applicationContext.xml:
        <!--配置数据源-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/tie</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>org/tie/vo/User.hbm.xml</value>
</list>
</property>
</bean>web.xml:
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>3</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>3</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>User.hbm.xml:
    <class name="org.tie.vo.User" table="user" catalog="tie">
        <id name="id" type="java.lang.Integer">
            <column name="id" />
            <generator class="native" />
        </id>
        <property name="username" type="java.lang.String">
            <column name="username" length="10" not-null="true" />
        </property>
        <property name="password" type="java.lang.String">
            <column name="password" length="10" not-null="true" />
        </property>
        <property name="email" type="java.lang.String">
            <column name="email" length="50" not-null="true" />
        </property>
    </class>出错信息:
信息: Illegal access: this web application instance has been stopped already.  Could not load java.net.BindException.  
信息: Illegal access: this web application instance has been stopped already.  Could not load com.mysql.jdbc.Util. 希望高手能给小弟指点一二,最好在xml配置文件中给出注释.
如果信息提供不全,请提示我加入.

解决方案 »

  1.   

    我始终想不通一个问题--
    为什么总有人--
    在J2SE都没有搞清楚之前就搞J2EE
    在JSP/SERVLET都没搞清楚前就搞STRUTS
    在SQL都没搞清楚前就搞HIBERNATE
    在接口和类都没搞清楚前就搞SPRING
      

  2.   


    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    org.hibernate.dialect.MySQLDialect
    </prop>
    <prop key="hibernate.hbm2ddl.auto">create</prop>
    </props>
    </property> 至于错误看下这贴http://diyutaizi3721.javaeye.com/blog/298615
      

  3.   

    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    org.hibernate.dialect.MySQLDialect
    </prop>
    prop key="hibernate.hbm2ddl.auto">create</prop>--自动创建表
    </props>
    </property> 
      

  4.   

    运行完上面程序启动tomcat的时候,报以下错误,是为什么?严重: action: null
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.apache.commons.pool.impl.GenericObjectPool: method <init>()V not found
    Caused by: java.lang.NoSuchMethodError: org.apache.commons.pool.impl.GenericObjectPool: method <init>()V not found
      

  5.   

    楼上几位回答的都对!这个问题好像经常有人问哦!搜索下CSDN原来的帖子!
      

  6.   

           如果有hibernate.cfg.xml文件
            在main方法里写:
          Configuration configuration = new Configuration().configure("/hibernate.cfg.xml");
            SchemaExport se = new SchemaExport(configuration);
            se.create(true, true);
          Spring与Hibernate集成完全可以分离文件
        
           如果把hibernate.cfg.xml的配置文件放到了Spring中就不能自动生成表了
       
           因为自动生成表的原理是:
             读hibernate.cfg.xml配置文件来生成的!
      

  7.   

    hibernate.cfg.xml不是已集成在spring配置文件中了吗?生成表都是由spring来管理
    交给spring管理不需要hiberate.cfg.xml