计算机学习积累

----转载有理,转载是想研究,想研究才会看,看了才会有感想,转载后我有时会写一些自己的感受
数据加载中……

我的项目的结构和配置文件

   学习java有段时间了,最近自己根据网上的资料自己搭了一个项目的,结构是这样的。
一、项目结构是这样的:
   (1)前台展现用的是spring mvc ,因为它比较简单,比起struts来,它更灵活一些,等以会struts ti出来后,可能会用。
    (2)管理bean ,是用的spring做为容器
     (3)持久层用的是ibatis,没有用hibernate的原因是不想再学一门语言了,HSQL太麻烦了,ibatis更加灵活好用一些。
二、项目在eclipse里的结构图:


三、各配置文件的内容:
 1.首先是web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
 xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 <context-param>
        <param-name>webAppRootKey</param-name>
        <param-value>test1.root</param-value>
    </context-param>
    <context-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>classpath:applicationContext.xml,/WEB-INF/test-servlet.xml</param-value>
    </context-param>
   
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>gb2312</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>*.do</url-pattern>
    </filter-mapping>
   
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
   
    <servlet>
        <servlet-name>test</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>test</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
   
    <!--session 超时-->
    <session-config>
        <session-timeout>10</session-timeout>
    </session-config>

    <!--默认首页-->
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>
2.spring的配置文件,主配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations">
   <list>
    <value>classpath:jdbc.properties</value>
   </list>
  </property>
 </bean>
 <!-- =======事务管理======== -->
 <bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
    abstract="true">
  <property name="transactionManager" ref="transactionManager"/>
  <property name="transactionAttributes">
   <props>
    <prop key="insert*">PROPAGATION_REQUIRED</prop>
    <prop key="update*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
   </props>
  </property>
 </bean>
 <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}"/>
 </bean>
 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource"/>
 </bean>
 <!-- ===========IBATIS SQLMAP配置============== -->
 <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
  <property name="configLocation" value="classpath:sql-map-config.xml"/>
  <property name="dataSource" ref="dataSource"/>
 </bean>
 
 <bean id="userManager" class="wh.logic.UserManager">
  <property name="sqlMapClient" ref="sqlMapClient"/>
 </bean>
</beans>
3.spring的servlet配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
 <bean id="methodNameResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
        <property name="paramName">
            <value>action</value>
        </property>
        <property name="defaultMethodName">
            <value>index</value>
        </property>
    </bean>
 <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    </bean>
   
    <bean name="/userController.do" class="wh.servlet.UserController">
     <property name="methodNameResolver">
            <ref bean="methodNameResolver"/>
        </property>
    </bean>
</beans>
4.ibatis配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
    "http://www.ibatis.com/dtd/sql-map-config-2.dtd">

<sqlMapConfig>
 <sqlMap resource="wh/domain/User.xml"/>
</sqlMapConfig>


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd">

<sqlMap namespace="User">

  <resultMap id="result" class="wh.domain.UserBean">
    <result property="id" column="id" columnIndex="1"/>
    <result property="name" column="name" columnIndex="2"/>
    <result property="pwd" column="pwd" columnIndex="3"/>
  </resultMap>

  <select id="getUser" resultMap="result">
    select id,name,pwd from [user] where id = #value#
  </select>

  <select id="getUserList" resultMap="result">
    select id,name,pwd from [user]
  </select>

</sqlMap>
5.log4j配置文件
log4j.rootLogger=info, stdout


log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%t] %d %p [%c] - %m%n

log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=${srping.root}/WEB-INF/spring.log
log4j.appender.logfile.MaxFileSize=512KB
# Keep three backup files.
log4j.appender.logfile.MaxBackupIndex=3
# Pattern to output: date priority [category] - message
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n

6.jdbc.propertis
# Properties file with JDBC-related settings.
# Applied by PropertyPlaceholderConfigurer from "dataAccessContext-local.xml".
# Targeted at system administrators, to avoid touching the context XML files.

jdbc.driverClassName=net.sourceforge.jtds.jdbc.Driver
jdbc.url=jdbc:jtds:sqlserver://127.0.0.1:1433/test
jdbc.username=sa
jdbc.password=123123

posted on 2006-06-27 17:33 freebird 阅读(339) 评论(1)  编辑  收藏 所属分类: java

评论

# re: 我的项目的结构和配置文件  回复  更多评论   

学好技术,未来在自己手中
2008-07-24 21:31 | 天堂明月

只有注册用户登录后才能发表评论。


网站导航: