eclipse 新建 maven 项目 添加 spring hibernate 的配置文件 详情

主要配置文件

pom.xml 项目的maven 配置文件 管理项目所需 jar 依赖支持

web.xml 项目的总 配置文件  :添加 spring和hibernate 支持

applicationContext.xml   hibernate的配置文件

sping-servlet.xml spring的配置文件

jdbc-properties 数据库连接属性 文件

------------------------------pom.xml 开始----------------------------------------------

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.o2ole</groupId>
    <artifactId>CheLL</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>CheLL</name>
    <url>http://www.o2ole.com</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <finalName>CheLL</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>UTF8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <organization>
        <name>北京欧乐互动网络科技有限公司</name>
        <url>http://www.o2ole.com</url>
    </organization>

    <!-- 发布支持 -->
    <distributionManagement>
        <repository>
            <id>releases</id>
            <name>Internal Releases</name>
            <url>http://192.168.0.254:8080/nexus/content/repositories/releases</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <name>Internal Snapshots</name>
            <url>http://192.168.0.254:8080/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>

    <dependencies>
        <!-- junit的依赖 -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <!-- 日志的依赖 -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.7</version>
        </dependency>
        <!-- web模块类库的依赖 -->
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>
        <!-- 持久化类库的依赖 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.25</version>
        </dependency>
        <!-- spring模块类库的依赖 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>4.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>4.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>4.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.1.1.RELEASE</version>
        </dependency>
        <!-- hibernate的依赖 -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.6.Final</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <!-- jackson的依赖 -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.4.3</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.4.3</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.4.3</version>
        </dependency>
        <!-- sybot的依赖 -->
        <dependency>
            <groupId>org.sybot</groupId>
            <artifactId>webbase</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>

------------------------------pom.xml 结束----------------------------------------------

------------------------------web.xml 开始----------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://xmlns.jcp.org/xml/ns/javaee"
	xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
	version="3.1">

	<display-name>CheLL</display-name>

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext.xml</param-value>
	</context-param>

	<!-- 增加字符集过滤器,解决中文乱码问题 -->
	<filter>
		<filter-name>CharacterFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
		<init-param>
			<param-name>forceEncoding</param-name>
			<param-value>true</param-value>
		</init-param>
	</filter>

	<!-- 启动SPring窗口的监听器 -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<!-- Spring MVC配置 -->
	<servlet>
		<servlet-name>spring</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:spring-servlet.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>spring</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>

	<!-- 分页过滤器 -->
	<filter>
		<filter-name>PaginationFilter</filter-name>
		<filter-class>org.sybot.web.easyui.PaginationFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>PaginationFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<!-- 应用过滤器 -->
	<filter>
		<filter-name>ApplicationContextFilter</filter-name>
		<filter-class>org.sybot.web.filter.ApplicationContextFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>ApplicationContextFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<filter>
		<filter-name>openSessionInViewerFilter</filter-name>
		<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>openSessionInViewerFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
</web-app>

  

------------------------------web.xml 结束----------------------------------------------

------------------------------applicationContext.xml 开始----------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<!-- 引用Spring的多个Schema格式定义文件 -->
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.1.xsd
                        http://www.springframework.org/schema/tx
                        http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
                        http://www.springframework.org/schema/aop
                        http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">

	<!-- 打开Spring的Annotation支持 -->
	<context:annotation-config />
	<!-- 设定Spring 去哪些包中找Annotation -->
	<context:component-scan base-package="com.o2ole.chell" />

	<!-- 导入Src目录下的jdbc.properties文件 -->
	<context:property-placeholder location="classpath:jdbc.properties" />
	<!-- 引入属性文件 - -> <context:property-placeholder location="/WEB-INF/application.properties"/ -->

	<!-- 定义数据源 -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName" value="${jdbc.driverClassName}" />
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
		<!-- 配置连接池的初始值 -->
		<property name="initialSize" value="5" />
		<!-- 当最小空闲时,当连接少于minIdle时会自动去申请一些连接 -->
		<property name="minIdle" value="2" />
		<property name="maxActive" value="100" />
		<property name="maxIdle" value="20" />
		<property name="maxWait" value="1000" />
	</bean>

	<!-- 定义hibernate相关配置 -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
		<!-- 注入数据源 -->
		<property name="dataSource" ref="dataSource" />
		<!-- 设置Spring取那个包中查找相应的实体类 -->
		<property name="packagesToScan">
			<list>
				<value>org.sybot.vm.domain</value>
			</list>
		</property>

		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.hbm2ddl.auto">update</prop>
				<prop key="hibernate.format_sql">true</prop>
			</props>
		</property>
	</bean>

	<!-- 配置Spring的事务处理 -->
	<!-- 创建事务管理器 -->
	<bean id="txManager"
		class="org.springframework.orm.hibernate4.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>

	<tx:annotation-driven transaction-manager="txManager" />
</beans>

  

------------------------------applicationContext.xml 结束----------------------------------------------

------------------------------sping-servlet.xml 开始----------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.1.xsd
                        http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

    <!-- 配置静态资源,直接映射到对应的文件夹 -->
    <mvc:resources mapping="/res/**" location="/WEB-INF/resources/" />

    <!-- 扫描类包,将标注Spring注解的类自动转化bean,同时完成Bean的注入 -->
    <mvc:annotation-driven />
    <context:component-scan base-package="com.o2ole.chell" />

    <!-- 配置视图解析器,将ModelAndView及客串解析为具体的页面 -->
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/page/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <bean
        class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                <ref bean="mappingJacksonHttpMessageConverter" />
            </list>
        </property>
    </bean>
    <bean id="mappingJacksonHttpMessageConverter"
        class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>text/html;charset=UTF-8</value>
            </list>
        </property>
    </bean>
</beans>

------------------------------sping-servlet.xml 结束----------------------------------------------

------------------------------jdbc-properties 开始----------------------------------------------

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url = jdbc\:mysql\://192.168.0.200\:3308/chell_center
jdbc.username = yd
jdbc.password = 123456

------------------------------jdbc-properties 结束----------------------------------------------

时间: 2024-10-10 21:13:07

eclipse 新建 maven 项目 添加 spring hibernate 的配置文件 详情的相关文章

eclipse新建maven项目(2)

本篇博文是继续之前的博文eclipse新建maven项目(1),那篇博文不在随笔在文章中.首先按照之前那篇博文进行创建maven项目操作,一系列操作下来之后发现刷新项目后会报错: 别急哈,可以解决. 之后选中项目,鼠标右键: 之后升级maven项目即可看到错误解决了,没有了红叉提示了.针对于每次升级maven项目后,项目的jdk版本都会变成1.5版本的问题,其实是可以设置的,只需要在pom.xml文件中添加下面这串代码即可实现每次更新maven项目后不需要手动调整jdk版本. 1 <!-- 源码

eclipse 新建 maven 项目 步骤(初级入门新手)

安装 maven(百度) 和在eclipse 中svn(上一篇) 修改 maven 本地仓库 eclipse 属性 maven--> installations-->添加新的 自定义安装的 maven 指向 自定义安装的 maven 路径 --> user settings 修改global settings 和usersettings 改为 自定义安装的 maven 路径下 的conf-->settings.xml settings.xml 里面修改本地仓库地址(自已百度怎么修改

eclipse新建maven项目出现红叉解决办法

新建的maven项目,项目内代码及pom.xml没有任何问题,但项目上就是有红叉,看起来很不舒服.这时点开Markers(Window–>show veiw–>Markers),查看错误的详细信息,信息上:Project configuration is not up-to-date with pom.xml. Run project configuration update. 原因是没有更新pom.xml文件. 按照提示做即可:项目右击–>Maven–>Update Projec

eclipse新建maven项目报错The superclass &quot;javax.servlet.http.HttpServlet&quot; was not found on the Java Build Path的解决方案

具体表现为: 使用Eclipse+Maven建立了一个Javaweb工程,JSP页面顶端出现“红色”的报错信息:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path. 解决方法: 在pom.xml中的  <build></build>中  添加: <plugins> <!-- 编码和编译和JDK版本 --> <plug

eclipse新建maven项目出错

1.错误:Could not resolve archetype org.apache.maven.archetypes:maven-archetype-quickstart:RELEASE from any of the configured repositories.Could not resolve artifact org.apache.maven.archetypes:maven-archetype-quickstart:pom:RELEASEFailed to resolve ver

eclipse新建maven项目和聚合项目

1.new maven project :  next 2.勾选 create a simple project  :  next 3.Group Id:项目的包路径 如com.jiayou.zjl,之后创建的Controller.Service等包都在该包路径下. Artifact Id:项目名称. Packaging:以何种方式打包.一般父项目就pom,父项目里可以什么都没有只有一个pom.xml:子项目用war finish; 4.如下创建成功后的父项目如下,可把src删除. 5.下面创建

maven项目中Spring整合Shiro配置文件(示例)

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schem

Eclipse下新建Maven项目、自动打依赖jar包

当我们无法从本地仓库找到需要的构件的时候,就会从远程仓库下载构件至本地仓库.一般地,对于每个人来说,书房只有一个,但外面的书店有很多,类似第,对于Maven来说,每个用户只有一个本地仓库,但可以配置访问很多远程仓库. Eclipse *版本 Eclipse *下载 强烈推荐书籍:Maven实战   许晓斌著.目前是第一版 注意:最新版本的Eclipse代号Mars,已经直接集成了Maven,所以无需安装m2Eclipse插件. Eclipse下新建Maven项目 1.下载Maven安装包 进入M

eclipse下新建maven项目

eclipse下新建maven项目 1.1下载maven安装包 进入Maven官网的下载页面:http://maven.apache.org/download.cgi,如下图所示:\ 选择当前最新版本:"apache-maven-3.3.9-bin.zip",下载到本地,解压缩到本地磁盘下. 1.2 配置 修改默认的本地仓库位置 进入Maven安装目录下的conf子目录中,打开settings.xml进行配置修改. Maven默认的本地仓库位置是当前用户工作目录下的".m2/