求助:最近弄了一个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配置文件中给出注释.
如果信息提供不全,请提示我加入.
并且在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配置文件中给出注释.
如果信息提供不全,请提示我加入.
为什么总有人--
在J2SE都没有搞清楚之前就搞J2EE
在JSP/SERVLET都没搞清楚前就搞STRUTS
在SQL都没搞清楚前就搞HIBERNATE
在接口和类都没搞清楚前就搞SPRING
<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
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
prop key="hibernate.hbm2ddl.auto">create</prop>--自动创建表
</props>
</property>
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
在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配置文件来生成的!
交给spring管理不需要hiberate.cfg.xml