java开发中所有的配置文件,持续更新

来源:互联网 发布:java getclassloader 编辑:程序博客网 时间:2024/05/16 09:52

1. springmvc.xml          SpringMVC框架的配置文件

<?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:mvc="http://www.springframework.org/schema/mvc"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.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd "><!-- 配置视图解析器 --><bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"><!-- 通过setter方法注入前缀 --><property name="prefix" value="/jsps/"></property><!-- 通过setter方法注入后缀 --><property name="suffix" value=".jsp"></property></bean></beans>

2. beans.xml      spring的配置文件

<?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:mvc="http://www.springframework.org/schema/mvc"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.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd "><!-- 数据源 --><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="driverClass" value="com.mysql.jdbc.Driver"></property><property name="jdbcUrl" value="jdbc:mysql://localhost:3306/springmvc_hibernate"></property><property name="user" value="root"></property><property name="password" value="root"></property><property name="maxPoolSize" value="50"></property><property name="minPoolSize" value="30"></property><property name="initialPoolSize" value="30"></property></bean><!-- 本地会话工厂bean --><bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><property name="dataSource" ref="dataSource"/><!-- 注入hibernate属性 --><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop><prop key="hibernate.hbm2ddl.auto">update</prop><prop key="hibernate.show_sql">true</prop></props></property><!-- 注册hbm映射文件 --><property name="mappingDirectoryLocations"><list><value>classpath:cn/itcast/domain</value></list></property></bean><!-- 事务管理器 --><bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory"/></bean><!-- 注册一个hibernate模块对象,注入给Dao --><bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"><property name="sessionFactory" ref="sessionFactory"/></bean><!-- 配置组件扫描 --><context:component-scan base-package="cn.itcast"></context:component-scan><!-- 注解驱动  --><mvc:annotation-driven/><!-- 支持事务注解 --><tx:annotation-driven transaction-manager="txManager"/></beans>

3. log4j.properties

### direct log messages to stdout ###log4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.Target=System.errlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n### direct messages to file mylog.log ###log4j.appender.file=org.apache.log4j.FileAppenderlog4j.appender.file.File=c\:mylog.loglog4j.appender.file.layout=org.apache.log4j.PatternLayoutlog4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n### set log levels - for more verbose logging change 'info' to 'debug' ###log4j.rootLogger=info, stdout
4. hmb.xml

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"><hibernate-mapping><class name="cn.itcast.domain.User" table="itcast_user"><id name="id" length="32"><generator class="uuid"/></id><property name="name" length="32"/><property name="age"/></class></hibernate-mapping>


5. mybatis 中的 UserMapper.xml配置文件

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="cn.itcast.domain.User"><!-- 当前配置文件中的sql使用缓存 --><cache type="org.mybatis.caches.ehcache.EhcacheCache"/><!-- 提取公共字段 --><sql id="allColumns">id , name , age ,address</sql><!-- select标签中写查询语句 --><!-- id:当前sql语句的唯一标识,在java程序中通过id指定要执行的sqlparameterType:参数类型,java程序要传入的参数的类型resultType:结果类型,当sql执行完成后由框架包装成什么样的类型返回 --><select useCache="true" id="selectUserById" parameterType="int" resultType="User">select <include refid="allColumns"/> from itcast_user where id = #{id}</select><!-- 查询所有User --><select id="selectAll" resultType="cn.itcast.domain.User">select <include refid="allColumns"/> from itcast_user</select><!-- 根据id删除User --><delete id="deleteUserById" parameterType="int">delete from itcast_user where id = #{id}</delete><!-- 插入数据 --><insert id="saveUser" parameterType="cn.itcast.domain.User">insert into itcast_user(name,age,address) values (#{name},#{age},#{address})</insert><!-- 根据id修改User --><update id="updateUserById" parameterType="cn.itcast.domain.User">update itcast_user set name = #{name},age = #{age},address = #{address}where id = #{id}</update><!-- 插入数据 --><insert id="saveUserUseMap" parameterType="hashmap">insert into itcast_user(name,age,address) values (#{name},#{age},#{address})</insert><!-- 查询数据,返回结果为Map类型 --><select id="selectUserById4Map" resultType="hashmap" parameterType="int">select * from itcast_user where id = #{id}</select><!-- 根据name进行模糊查询 --><select id="selectUsersByNameLike" parameterType="User" resultType="User">select * from itcast_user where name like '%${name}%'</select><!-- 根据name进行模糊查询 --><select id="selectUsersByNameLike2" parameterType="hashmap" resultType="User">select * from itcast_user where name like '%${name}%'</select><!-- 组合条件查询 --><select id="selectUsersByCondition" parameterType="User" resultType="User">select * from itcast_user where 1 = 1 <if test="id != null">and id = #{id}</if><if test="name != null">and name like '%${name}%'</if><if test="age != null">and age = #{age}</if><if test="address != null">and address = #{address}</if></select><!-- 组合条件查询 --><select id="selectUsersByCondition2" parameterType="User" resultType="User">select * from itcast_user <where><if test="id != null">and id = #{id}</if><if test="name != null">and name like '%${name}%'</if><if test="age != null">and age = #{age}</if><if test="address != null">and address = #{address}</if></where></select><!-- 动态更新语句 --><update id="updateUserByIdCondition" parameterType="User">update itcast_user <set><if test="name != null">name = #{name},</if><if test="age != null">age = #{age},</if><if test="address != null">address = #{address},</if></set>where id = #{id}</update><!-- 批量插入数据 --><insert id="insertBatch" parameterType="map">insert into itcast_user (name,age,address)values<foreach collection="userList" item="user" separator=",">(#{user.name},#{user.age},#{user.address})</foreach></insert><!-- 一次查询多个数据 --><select id="selectUsersByIds" parameterType="map" resultType="User">select * from itcast_user where id in <foreach collection="userIds" item="userId" open="(" close=")" separator=",">#{userId}</foreach></select></mapper>

6.  ehcache.xml 二级缓存配置文件

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd">    <diskStore path="java.io.tmpdir"/>    <defaultCache            maxElementsInMemory="10000"            eternal="false"            timeToIdleSeconds="120"            timeToLiveSeconds="120"            maxElementsOnDisk="10000000"            diskExpiryThreadIntervalSeconds="120"            memoryStoreEvictionPolicy="LRU">        <persistence strategy="localTempSwap"/>    </defaultCache></ehcache>

7. sqlMapConfig.xml 

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration><typeAliases><!-- 定义别名 --><typeAlias type="cn.itcast.ssm.domain.User" alias="User"/></typeAliases><!-- 注册项目中使用到的sql映射文件 --><mappers><mapper resource="cn/itcast/ssm/domain/UserMapper.xml" /></mappers></configuration>

8. generator.xml (Mybatis自动生成)

<?xml version="1.0" encoding="GBK"?>  <!DOCTYPE generatorConfiguration    PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"    "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">  <!-- Mybatis 官方生成工具 -->  <generatorConfiguration>      <!-- classPathEntry:数据库的JDBC驱动 -->     <classPathEntry location="E:/Workspaces/rapid-genertor/WebRoot/WEB-INF/lib/mysql-connector-java-5.1.24.jar" />    <context id="DB2Tables" targetRuntime="MyBatis3">          <!-- 去除自动生成的注释 -->          <commentGenerator>              <property name="suppressAllComments" value="true" />          </commentGenerator>          <jdbcConnection driverClass="com.mysql.jdbc.Driver"  connectionURL="jdbc:mysql://127.0.0.1:3306/uebuycar_test" userId="root"              password="uebuycar">          </jdbcConnection>              <javaTypeResolver>              <property name="forceBigDecimals" value="false" />          </javaTypeResolver>          <!-- targetProject:自动生成代码的位置 -->          <javaModelGenerator targetPackage="com.xuanyan.uebuycar.pojo"  targetProject="E:/Workspaces/uebuycar2.0/src">              <property name="enableSubPackages" value="true" />              <property name="trimStrings" value="true" />          </javaModelGenerator>              <sqlMapGenerator targetPackage="com.xuanyan.uebuycar.dao.sqlmap"  targetProject="E:/Workspaces/uebuycar2.0/src">              <property name="enableSubPackages" value="true" />          </sqlMapGenerator>              <javaClientGenerator type="XMLMAPPER"  targetPackage="com.xuanyan.uebuycar.dao" targetProject="E:/Workspaces/uebuycar2.0/src">              <property name="enableSubPackages" value="true" />          </javaClientGenerator>          <!-- tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名 -->          <!-- <table schema="" tableName="car_article"></table>                     <table schema="" tableName="car_loan_model"></table>          <table schema="" tableName="car_replace"></table>         </context>    </generatorConfiguration>  


0 0
原创粉丝点击