SSH整合开发的一些总结

最近做了一个SSH正好的项目,把一些遇到的bug记录下来,给大家共享,同时也给自己上一课
1.程序运行不起来,报Unsupported major.minor version 51.0错误,这是因为编译文件的jdk版本和当前jdk的版本不一致导致的,也也能是由于1.8的jdk太高,有的集成框架还没来得及更新,所以最好使用1.7或1.6的jdk,解决办法是更改编译器的版本,使其符合原来编译的版本即可
2.出现log4j:
WARN No appenders could be found for logger
(org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
解决办法是创建在src下建立log4j.properties,内容如下
这里写图片描述
并且log4j的jar包最好要在1.2.12之后
3.使用@Resource@Transactional等注解时,必须要在beans.xml文件中配置

其作用是用于激活在spring容器(spring.xml)中注册过的bean上面的注解,没注册过的没有用。其实他做工作是
他的作用显式地向 Spring 容器注册
AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、
PersistenceAnnotationBeanPostProcessor 以及 RequiredAnnotationBeanPostProcessor 这 4 个BeanPostProcessor。
注册这4个 BeanPostProcessor的作用,就是为了你的系统能够识别相应的注解。
另外,其实使用(它包含了上面一种方式的全部功能)采用扫描的方式用注解的方式进行注入更合理更方便
4.采用ssh集成,必须在web.xml中声明
spring容器的配置文件位置和监听器,不然spring所做的一切配置付诸东流

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:beans.xml</param-value>
</context-param>
    <listener>  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

5.spring采用注解方式注入需要注意引入的jar包为
common.annotation.jar
jdbc用到的两个commons-dbcp.jar和commons.pool.jar

下面是SSH整合的整合bean.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:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd
           http://www.springframework.org/schema/tx 
           http://www.springframework.org/schema/tx/spring-tx.xsd 
           http://www.springframework.org/schema/aop 
           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
           <context:annotation-config/>
    <!-- 数据源 -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/ssh"/>
        <property name="username" value="root"/>
        <property name="password" value="*****"/>
        <property name="initialSize" value="1"/>
        <property name="maxActive" value="500"/>
        <property name="maxIdle" value="2"/>
        <property name="minIdle" value="1"/>
    </bean>
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
        <property name="dataSource" ref="dataSource"/>
        <property name="mappingResources">
            <list>
                <value>/edu/just/zjg/bean/Person.hbm.xml</value>
            </list>
        </property>
        <property name="hibernateProperties">
        <!--    <props>
                   <prop key="hibernate.dialect">
                   org.hibernate.dialect.MySQLDialect
                   </prop>
                   <prop key="hibernate.hbm2ddl.auto">
                   update
                   </prop>
                   <prop key="hibernate.show_sql">
                  true
                   </prop>
                   <prop key="hibernate.format_sql">
                  false
                   </prop>
             </props> -->
            <value>
            hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
                hibernate.hbm2ddl.auto=update
                hibernate.show_sql=true
                hibernate.format_sql=false
                hibernate.cache.use_second_level_cache=true
                hibernate.cache.user_query_cache=false
                hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
            </value>
        </property>
    </bean>
    <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    <tx:annotation-driven transaction-manager="txManager"/>
    <bean id="personService" class="edu.just.zjg.service.impl.PersonServiceBean">
    <!-- <property name="sessionFactory">
    <ref local="sessionFactory"/>
    </property> -->
    </bean>
    <bean id="personAction" class="edu.just.zjg.action.PersonAction"/>
</beans>

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>contextConfigLocation</param-name>
<param-value>classpath:beans.xml</param-value>
</context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

jar包(不一定是这些,仅作为参考):
这里写图片描述
这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值