关于service层得Dao注入,强烈求教!!!

salty_dish 2011-04-21 04:32:52
@Service

public class ScormDataHelper implements ScormDataTransferred{
@Autowired
private lesson_locationDAO objlesson_locationDAO ;

上面的dao中已经加上了repository注解
不知道为什么在调用dao中的方法是报空指针异常? 会有哪几种可能的原因?
...全文
304 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
jude_cn 2011-04-21
  • 打赏
  • 举报
回复
问问同事吧!!!
salty_dish 2011-04-21
  • 打赏
  • 举报
回复
其他的dao可以只是少了一层继承关系 这里也没有接口
jude_cn 2011-04-21
  • 打赏
  • 举报
回复
现在问题 其它dao的注入可不可以?如果可以,objlesson_locationDAO 这个是接口吗?如果是接口,有没有多个这个接口的实现配置到IOC里?
salty_dish 2011-04-21
  • 打赏
  • 举报
回复
我这个dao有继承结构:objlesson_locationDAO ----》fatherdao》grandfatherDao--hibernatedaosupport 是否会有影响
jude_cn 2011-04-21
  • 打赏
  • 举报
回复
我用Spring 3 不用setter
salty_dish 2011-04-21
  • 打赏
  • 举报
回复
默认不是通过constructor方式注入? 我的service没有针对dao的setter
XiangZhiLiu 2011-04-21
  • 打赏
  • 举报
回复
get and set method is Exists or null?
jude_cn 2011-04-21
  • 打赏
  • 举报
回复
<tx:annotation-driven /> 需要这个注解吧
jude_cn 2011-04-21
  • 打赏
  • 举报
回复
晕 这个是需要的。。
salty_dish 2011-04-21
  • 打赏
  • 举报
回复
是不是与<!-- <context:annotation-config /> -->被注掉有关
jude_cn 2011-04-21
  • 打赏
  • 举报
回复
有可能是AOP创建了实现lesson_locationDAO接口的代理。尝试下用@Qualifier注解指明Bean id
salty_dish 2011-04-21
  • 打赏
  • 举报
回复
<?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:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context" 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/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-autowire="byName" default-lazy-init="false">

<!-- 定义受环境影响易变的变量 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<!-- 标准配置 -->
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>

<!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 -->
<context:component-scan base-package="com.ulearning.ulms" />
<!-- <context:annotation-config /> -->

<!-- 数据源配置,使用应用内的DBCP数据库连接池 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<!-- Connection Info -->
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />

<!-- Connection Pooling Info -->
<property name="initialSize" value="5" />
<property name="maxActive" value="100" />
<property name="maxIdle" value="30" />
<property name="maxWait" value="500" />
<property name="defaultAutoCommit" value="false" />
</bean>

<!-- Hibernate配置 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.connection.release_mode">${hibernate.connection.release_mode}</prop>
</props>
</property>
<property name="packagesToScan" value="com.ulearning.ulms." />
</bean>
<!--
<bean id="datesource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:@192.168.0.209:1521:orcl">
</property>
<property name="username" value="ulms_bankedu"></property>
<property name="password" value="ulms_bankedu"></property>
</bean>
<bean id="SessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="datesource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property>
<property name="configLocation"
value="hibernate.cfg.xml">
</property>
</bean>
-->

<!-- 事务管理器配置,单数据源事务 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<!-- 使用annotation定义事务 -->
<!--
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
-->

<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* com.ulearning.ulms..*.*Manager.*(..))" advice-ref="txAdvice" />
<aop:advisor pointcut="execution(* com.ulearning.ulms..*.*Dao.*(..))" advice-ref="txAdvice" />
</aop:config>

<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="query*" read-only="true" />
<tx:method name="is*" read-only="true" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>


</beans>
  • 打赏
  • 举报
回复
贴Spring配置文件
jude_cn 2011-04-21
  • 打赏
  • 举报
回复
有可能是你的DAO有多种实现

67,516

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧