亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁/技術文章
文章詳情頁

Spring4.3.7注解 @Autowired java.lang.NullPointerException

瀏覽:72日期:2023-12-31 16:34:17

問題描述

UserAction中通過@Autowired注入UserServiceImpl無效,得到對象為空UserAction.java

@Namespace('/')@ParentPackage('struts-default')@Controllerpublic class UserAction extends ActionSupport implements ModelDriven<User> { private User user = new User(); public User getModel() {return this.user; } // ***************************** @Autowired private UserService userService; @Action(value = 'userAction_add', results = { @Result(name = 'add', location = '/success.jsp') }) public String add() {this.userService.saveUser(user);return 'add'; }}

UserServiceImpl.java

@Servicepublic class UserServiceImpl implements UserService { @Autowired private UserDao userDao; @Transactional public void saveUser(User user) {this.userDao.save(user); } @Transactional public void updateUser(User user) {this.userDao.update(user); } @Transactional public void deleteUser(User user) {this.userDao.delete(user); } @Transactional(readOnly = true) public User findUserById(Integer id) {return this.userDao.findById(id); } @Transactional(readOnly = true) public List<User> findAllUser() {return this.userDao.findAll(); }}

配置文件

<?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.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.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.xsd'> <!-- 掃描 com包--> <context:component-scan base-package='com'></context:component-scan> <context:annotation-config/> <!-- <context:property-placeholder location='classpath:redis.properties'/> <bean class='redis.clients.jedis.JedisPoolConfig'> <property name='maxIdle' value='${redis.pool.maxIdle}' /> <property name='maxTotal' value='${redis.pool.maxActive}' /> <property name='maxWaitMillis' value='${redis.pool.maxWaitMillis}' /> <property name='testOnBorrow' value='${redis.pool.testOnBorrow}' /> <property name='testOnReturn' value='${redis.pool.testOnReturn}' /> </bean> --><!-- 加載c3p0-db.properties --> <context:property-placeholder location='classpath:c3p0-db.properties' /> <!-- 配置dataSource數據源 --> <bean class='com.mchange.v2.c3p0.ComboPooledDataSource'><property name='driverClass' value='${jdbc.driverClass}'></property><property name='jdbcUrl' value='${jdbc.jdbcUrl}'></property><property name='user' value='${jdbc.user}'></property><property name='password' value='${jdbc.password}'></property> </bean><!-- 1 配置SessionFactory --> <bean class='org.springframework.orm.hibernate5.LocalSessionFactoryBean'><!-- 1.1 配置數據源 --><property name='dataSource' ref='dataSource'></property><!-- 1.2 其他配置項 ,要使用hibernate全屬性名,如果hibernate.不要省略 --><property name='hibernateProperties'> <props><prop key='hibernate.dialect'> org.hibernate.dialect.MySQL5Dialect </prop><prop key='hibernate.show_sql'>true</prop><prop key='hibernate.format_sql'>true</prop><prop key='hibernate.hbm2ddl.auto'>update</prop><prop key='javax.persistence.validation.mode'>none</prop><prop key='hibernate.current_session_context_class'>thread</prop><prop key=''></prop> </props></property><!-- 配置實體類 --><property name='packagesToScan'> <list><value>com.entity</value> </list></property> </bean> <!-- 配置hibernate模板,必須使用模板 --> <bean class='org.springframework.orm.hibernate5.HibernateTemplate'><!-- 通過工廠獲得session,操作PO類 --><property name='sessionFactory' ref='sessionFactory'></property> </bean> <!-- 事務管理 --> <!-- 事務管理器,就是平臺,spring工具產生, 依賴于使用 持久方案(hibernate、jdbc等) --> <bean class='org.springframework.orm.hibernate5.HibernateTransactionManager'><property name='sessionFactory' ref='sessionFactory'></property> </bean> <!-- 將事務管理注冊spring * proxy-target-class='true': 使用cglib * proxy-target-class='false':有接口將使用 jdk --> <tx:annotation-driven transaction-manager='txManager' /></beans>

問題解答

回答1:

請保證UserServiceImpl在被掃描的包內。

回答2:

注解的掃描有問題

回答3:

我建議你看看UserDao是否正確注入,這條鏈子上有一個注入失敗了就會導致整體創建失敗

標簽: java
相關文章:
主站蜘蛛池模板: 欧美欲妇激情视频在线 | 国产福利一区视频 | 中文字幕在线播放不卡 | 拍拍拍精品视频在线观看 | 成人做爰又黄又爽免费视频 | 高清国产精品入口麻豆 | 三级黄色小视频 | 国产精亚洲视频 | 国产精品巨乳 | 女人午夜色又刺激黄的视频免费 | 国产成人成人一区二区 | 婷婷综合网站 | 亚洲一二三四 | 国产在线观看精品香蕉v区 国产在线每日更新 | 日本人强jizzjapanesehd | 黄色片一级免费 | 国产在线观看黄 | ww亚洲ww在线观看国产 | 日韩精品观看 | 全免费a级毛片免费看视频免 | 国产在线观免费观看 | 国内精品自在欧美一区 | 久久国产精品-国产精品 | 韩国女主播精品一区二区 | 国产午夜高清一区二区不卡 | 毛片三级在线观看 | 国产极品在线观看视频 | 国产tv在线观看 | 三极片免费看 | 五月天激激婷婷大综合丁香 | 97香蕉久久夜色精品国产 | 成人在线观看视频免费 | 手机看片自拍 | 国产精品污视频 | 国产精品黄在线观看观看 | 精品一久久香蕉国产线看观看下 | 国产亚洲精品成人一区看片 | 嫩草视频在线看 | 亚洲精品tv | 亚洲国产精品免费在线观看 | 亚洲成人99 |