开发者社区> 问答> 正文

spring注解 @service 使用报错. ?报错

3个报错:
Failed to read candidate component class: file [D:\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\bootstrap-3.3.5\WEB-INF\classes\fish\code\dao\user\UserDao.class]; nested exception is org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [D:\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\bootstrap-3.3.5\WEB-INF\classes\fish\code\dao\user\UserDao.class]; nested exception is java.lang.IllegalArgumentException

ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [D:\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\bootstrap-3.3.5\WEB-INF\classes\fish\code\dao\user\UserDao.class]; nested exception is java.lang.IllegalArgumentException

BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

结构:
图片说明

代码:
@Repository
public class UserDao extends SqlSessionDaoSupport{

public UserModel getUserModel(){
    return this.getSqlSession().selectOne("UserModel.getUserById",1L);
}

}

@Service
public class UserService {
@Resource
private UserDao userDao;
public UserModel getUserModel(){
return userDao.getUserModel();
}
}

@WebServlet(name = "userServlet", urlPatterns = { "/user" })
public class UserServlet extends HttpServlet {
public void init() throws ServletException {
WebApplicationContext context = WebApplicationContextUtils
.getWebApplicationContext(getServletContext());
this.setUserService((UserService) context.getBean("userService"));
}
}

spring配置扫描
之后就报上边3个错.

求大神指点.

展开
收起
爱吃鱼的程序员 2020-06-23 00:45:26 614 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    写上这句话就报错.
    不写这句话程序可以跑起来,但是在servlet里边获取不到userService.

    应该是你UserDao这个类所对应的xml配置错误导致!好好检查下

    2020-06-23 00:45:42
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载

相关实验场景

更多