问题描述
- spring注解 @service 使用报错.
-
3个报错:
Failed to read candidate component class: file [D:workspace.metadata.pluginsorg.eclipse.wst.server.coretmp1wtpwebappsbootstrap-3.3.5WEB-INFclassesfishcodedaouserUserDao.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.pluginsorg.eclipse.wst.server.coretmp1wtpwebappsbootstrap-3.3.5WEB-INFclassesfishcodedaouserUserDao.class]; nested exception is java.lang.IllegalArgumentExceptionASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [D:workspace.metadata.pluginsorg.eclipse.wst.server.coretmp1wtpwebappsbootstrap-3.3.5WEB-INFclassesfishcodedaouserUserDao.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个错.求大神指点.
解决方案
写上这句话就报错.
不写这句话程序可以跑起来,但是在servlet里边获取不到userService.
解决方案二:
应该是你UserDao这个类所对应的xml配置错误导致!好好检查下