@H_502_1@我有这个问题,我无法解决.
@H_502_1@从我的@Controller,我可以轻松访问我自动连接的@Service类,并且没有问题.
但是当我从没有注释的单独类中执行此操作时,它会给我一个NullPointerException. @H_502_1@我的控制器(工程) – @H_502_1@
但是当我从没有注释的单独类中执行此操作时,它会给我一个NullPointerException. @H_502_1@我的控制器(工程) – @H_502_1@
@Controller public class UserController { @Autowired UserService userService;...
@H_404_13@ @H_502_1@我独立的Java类(不工作) – @H_502_1@public final class UsersManagementUtil { @Autowired UserService userService;
@H_404_13@ @H_502_1@要么 @H_502_1@@Autowired UserDao userDao;
@H_404_13@ @H_502_1@userService或userDao始终为null!
只是尝试其中任何一个有效. @H_502_1@我的组件扫描设置具有用于扫描的根级别包,因此应该没问题. @H_502_1@我的servlet上下文 – @H_502_1@factorybean">
sql">${hibernate.show_sql}@H_404_13@ @H_502_1@任何线索?
最佳答案
从Spring Reference 3.0起
@H_502_1@
@H_502_1@By default,classes annotated with@H_502_1@UsersManagementUtil应根据您的需要使用其中一个进行注释.
@Component
,@Repository
,@Service
,
@Controller
,or a custom annotation
that itself is annotated with
@Component
are the only detected
candidate components.