m0_37456570
陆南亭
采纳率0%
2017-02-15 20:29 浏览 1.2k

SSH搭建框架报空指针异常

我在进行SSH基础框架搭建的时候(就是还没有配置实体类),只是进行了整合配置,将事务管理和数据库连接配置在spring中,spring代码如下:
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:jdbc="http://www.springframework.org/schema/jdbc"  
xmlns:jee="http://www.springframework.org/schema/jee" 
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop" 
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">








 

将sessionFactory中配置数据库连接的时候,就是中将数据库连接引进来的时候,就会报空指针异常,各位大牛能解答吗(纯自学SSH),环境是:Windows+Tomcat+oracle(虚拟机)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答 默认 最新

  • qq997404392 伪墨 2017-07-07 06:10

    给你个applicationContext.xml配置文件的参考吧

    <?xml version="1.0" encoding="UTF-8"?>
    

    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: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/aop
    http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

    <!-- 1.配置数据源dataSource -->
    <bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource">
        <property name="url"
            value="jdbc:mysql://localhost:3306/weimo">
        </property>
        <property name="username" value="root"></property>
        <property name="password" value="19920528"></property>
    </bean>
    
    <!-- 2.配置sessionFactory,注入dataSource -->
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.MySQLDialect
                </prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
            </props>
        </property>
        <property name="mappingResources">
            <list>
                <value>com/weimo/hbm/User1.hbm.xml</value></list>
        </property></bean>
    
    <!-- 3.配置hibernate模板类,注入sessionFactory -->
    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
        <property name="sessionFactory">
            <ref bean="sessionFactory"/>
        </property>
    </bean>
    
    <!-- 4.配置userDao,注入hibernateTemplate -->
    <bean id="userDao" class="com.weimo.dao.UserDao">
        <property name="hibernateTemplate">
            <ref bean="hibernateTemplate"/>
        </property>
    </bean>
    
    <!-- 5.配置userService,注入userDao -->
    <bean id="userService" class="com.weimo.service.UserService">
        <property name="userDao">
            <ref bean="userDao"/>
        </property>
    </bean>
    
    <!-- 6.配置userAction,注入userService -->
    <bean id="userAction" class="com.weimo.action.UserAction">
        <property name="userService">
            <ref bean="userService"/>
        </property>
    </bean>
    
    <!-- 配置事务管理器 -->
    <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref bean="sessionFactory"/>
        </property>
    </bean>
    
    <!-- 配置事务通知 -->
    <tx:advice id="myAdvice" transaction-manager="txManager">
        <tx:attributes>
            <!-- 以get开头的方法都会受到事务管理 -->
            <tx:method name="get*" read-only="true" isolation="DEFAULT"/>
            <!-- 任意方法都会受到事务管理 -->
            <tx:method name="*" propagation="REQUIRED" isolation="DEFAULT"/>
        </tx:attributes>
    </tx:advice>
    
    <!-- 配置切入点以及和事务通知的绑定关系 -->
    <aop:config>
        <!-- public 任意返回值 com.weimo.service包下的所有类的所有方法名(任意参数) --> 
        <aop:pointcut expression="execution(public * com.weimo.service.*.*(..))" id="txPointcut"/>
        <aop:advisor advice-ref="myAdvice" pointcut-ref="txPointcut"/>
    </aop:config>
    

    点赞 1 评论 复制链接分享
  • wojiushiwo945you 毕小宝 2017-02-16 01:02

    没有异常信息,可能是你的配置文件有问题,从现在你给的信息不好定位错误呢。

    点赞 评论 复制链接分享

相关推荐