MyEclipse2014新建Web Project并配置SSH

来源:互联网 发布:java中布尔 编辑:程序博客网 时间:2024/06/05 18:43

环境:

myeclipse2014

win10

jdk1.7

tomcat8


1、创建一个web项目,FileNewWeb Project,设置如下:

finish项目新建完成

2、添加spring,右击项目名称选择:MyEclipseProject Facts [Capabilities]Install Spring Facet,如下:

3、添加hibernate,首先需要创建数据库连接,然后再添加Hibernate。此处以mysql为例

首先打开Database Explorer视窗:

新建连接

设置好后点击:Test Driver,测试成功显示:

next

新建成功,现在可以连接:

现在可以打开对应方案的表和视图等:

添加Hibernate,右击项目名称选择:MyEclipseProject Facts [Capabilities]Install Hibernate Facet,如下:

4、添加struts,右击项目名称选择:MyEclipseProject Facts [Capabilities]Install Apache Struts(2.x) Facet,如下:

SSH搭建完成:

发布网站,测试成功:






可能我们会用到自己下载的jar包,所以可以将下面几个jar包移除




在src创建hibernate.cfg.xml

内容如下

<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE hibernate-configuration PUBLIC          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools.                   --><hibernate-configuration><session-factory><property name="dialect">org.hibernate.dialect.MySQLDialect</property><property name="connection.url">jdbc:mysql://localhost:3306/sshtest</property><property name="connection.username">root</property><property name="connection.driver_class">com.mysql.jdbc.Driver</property><property name="myeclipse.connection.profile">mysql</property></session-factory></hibernate-configuration>


修改applicationContext.xml

内容如下

<?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"><!--指明hibernate配置文件的位置  --><bean id="sessionFactory"    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">   <property name="configLocation" value="classpath:hibernate.cfg.xml" /></bean>  </beans>


这样修改后,部署运行,能够正常运行



0 0
原创粉丝点击