2 qq 15720657 qq_15720657 于 2016.03.14 13:32 提问

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 13:33

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

u013772876
u013772876   2016.03.14 13:51

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

qq_15720657
qq_15720657 并不是, spring从3升到4就好了.
接近 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!