spring注解报空指针错误,求大神指点

yangzhiyong1314 2013-04-10 10:50:55
bean配置:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
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/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"
default-lazy-init="true">

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

<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/>

<bean id="dataSource_oracle"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl">
</property>
<property name="username" value="system"></property>
<property name="password" value="orcl"></property>

<property name="initialSize" value="1" />
<property name="maxActive" value="10" />
<property name="maxIdle" value="3" />
<property name="maxWait" value="100" />
<property name="poolPreparedStatements" value="true" />
<property name="defaultAutoCommit" value="false" />

</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource_oracle" />
</property>
<property name="namingStrategy">
<bean class="org.hibernate.cfg.ImprovedNamingStrategy" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9iDialect
</prop>
<prop key="jdbc.batch_size">1024</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="query.substitutions">true 1,false 0</prop>
<prop key="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider
</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
</props>
</property>

<!-- 添加实体BEAN包,注意写到具体目录-->
<!--
<property name="packagesToScan">
<list>
<value></value>
</list>
</property>
-->
</bean>

<!-- ***** TransactionManager *****-->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>

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

</beans>

web.xml配置

<listener>
<description>spring的log4j监听器</description>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<description>spring的bean销毁回收监听器</description>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>

<!-- 指定spring的配置文件,默认从web根目录寻找配置文件,我们可以通过spring提供的classpath:前缀指定从类路径下寻找 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/applicationContext*.xml</param-value>
</context-param>
<!-- 对Spring容器进行实例化 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

action注解

@SuppressWarnings({ "unused", "serial" })
public class UserinfoAction extends ActionSupport {
//@Autowired
@Resource
private IUserInfoService userInfo;

private String name="admin";
public String userInfo(){
name="123456";
name=userInfo.queryUserInfo();
return "success";
}
service注解
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserInfoService implements IUserInfoService {

public String queryUserInfo() {
System.out.println("00000000000");
return "654321";
}

}
spring注解报空指针错误,求大神指点
...全文
174 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
bayougeng 2013-09-02
  • 打赏
  • 举报
回复
异常栈呢?-
  • 打赏
  • 举报
回复
请问此问题解决了吗?我也出现了这样的问题。

50,530

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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