Spring注解@Inject不起作用

编程入门 行业动态 更新时间:2024-10-11 21:31:53
本文介绍了Spring注解@Inject不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有代码@Inject在一个类中可用,但在另一类中不可用. 这是我的代码:

I have the code @Inject works in one class but not in other. Here's my code:

  • context.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="www.springframework/schema/beans" xmlns:xsi="www.w3/2001/XMLSchema-instance" xmlns:context="www.springframework/schema/context" xsi:schemaLocation=" www.springframework/schema/beans www.springframework/schema/beans/spring-beans.xsd www.springframework/schema/context www.springframework/schema/context/spring-context.xsd "> <bean id="multipartResolver" class="org.springframework.web.multipartmons.CommonsMultipartResolver"></bean> <context:component-scan base-package="com.myfashions.services"/> <context:component-scan base-package="com.myfashions.dao"/> </beans>

  • SellerRetriever.java
  • public class SellerRetriever { @Inject UserDAO userDAO; ... ... }

    UserDAO类存在于com.myfashions.dao软件包中. @Inject在Seller.java中不起作用.有什么原因吗?

    UserDAO class is present in com.myfashions.dao package. @Inject is not working in Seller.java. Any reason why?

    推荐答案

    我发现了我的错误,我发布了此错误,因为万一有人遇到同样的问题.我使用新的运算符创建了SellerRetriver对象.如果使用新的运算符调用该特定类,则注入将不起作用.

    I found my mistake, I'm posting this because in case anyone has the same problem. I used new operator to create an SellerRetriver object. Inject won't work if new operator is used to call that particular class.

更多推荐

Spring注解@Inject不起作用

本文发布于:2023-10-26 07:06:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529425.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:注解   不起作用   Spring   Inject

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!