qq_15720657
qq_15720657
2016-03-14 05:32
采纳率: 0%
浏览 7.0k

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个错.

求大神指点.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • qq_15720657
    qq_15720657 2016-03-14 05:33

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

    点赞 评论
  • u013772876
    夜半无声 2016-03-14 05:51

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

    点赞 评论

相关推荐