Tomcat启动报错
来源:6-9 用户模块所有功能自测试
ILoveHelloWorld
2018-05-18
18-May-2018 18:17:28.187 严重 [RMI TCP Connection(3)-127.0.0.1] org.springframework.web.context.ContextLoader.initWebApplicationContext Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userManageController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.mmall.service.IUserService com.mmall.controller.backend.UserManageController.iUserService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'IUserService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.mmall.dao.UserMapper com.mmall.service.impl.UserServiceImpl.userMapper; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userMapper' defined in file [C:\apache-tomcat-9.0.5\webapps\mmall\WEB-INF\classes\com\mmall\dao\UserMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory': : Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext-datasource.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext-datasource.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'initialSize'; nested exception is java.lang.NumberFormatException: For input string: "${db.initialSize}"; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext-datasource.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext-datasource.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'initialSize'; nested exception is java.lang.NumberFormatException: For input string: "${db.initialSize}" at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401) at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:361) at sun.rmi.transport.Transport$1.run(Transport.java:200) at sun.rmi.transport.Transport$1.run(Transport.java:197) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:196) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.mmall.service.IUserService com.mmall.controller.backend.UserManageController.iUserService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'IUserService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.mmall.dao.UserMapper com.mmall.service.impl.UserServiceImpl.userMapper; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userMapper' defined in file [C:\apache-tomcat-9.0.5\webapps\mmall\WEB-INF\classes\com\mmall\dao\UserMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory': : Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext-datasource.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext-datasource.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'initialSize'; nested exception is java.lang.NumberFormatException: For input string: "${db.initialSize}"; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext-datasource.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext-datasource.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'initialSize'; nested exception is java.lang.NumberFormatException: For input string: "${db.initialSize}" at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289) ... 58 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'IUserService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.mmall.dao.UserMapper com.mmall.service.impl.UserServiceImpl.userMapper; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userMapper' defined in file [C:\apache-tomcat-9.0.5\webapps\mmall\WEB-INF\classes\com\mmall\dao\UserMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory': : Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext-datasource.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext-datasource.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'initialSize'; nested exception is java.lang.NumberFormatException: For input string: "${db.initialSize}"; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext-datasource.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext-datasource.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'initialSize'; nested exception is java.lang.NumberFormatException: For input string: "${db.initialSize}" at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1014) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:957) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:855) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480) ... 60 more //JavaBean出问题了?@Autowired以及相关的注解都写了呀!老师能不能给出具体点的解决方法?是不是Jar包问题?
3回答
-
想当厨师的码农
2018-08-08
我错误跟你一样,你解决了吗
00 -
ILoveHelloWorld
提问者
2018-05-19
db.driverLocation=../tools/mysql-connector-java-5.1.6-bin.jar db.driverClassName=com.mysql.jdbc.Driver db.url=jdbc:mysql://localhost:3306/mmall?characterEncoding=UTF-8 db.username=root db.password=123456 db.initialSize = 20 db.maxActive = 50 db.maxIdle = 20 db.minIdle = 10 db.maxWait = 10 db.defaultAutoCommit = true db.minEvictableIdleTimeMillis = 3600000 @Controller @RequestMapping("/user/") public class UserController { @Autowired private IUserService iUserService; @RequestMapping(value = "login.do",method = RequestMethod.POST) @ResponseBody public ServerResponse<User> login(String username, String password, HttpSession session){ ServerResponse<User> response=iUserService.login(username, password); if(response.isSuccess()){ session.setAttribute(Const.CURRENT_USER,response.getData()); } return response; } public interface IUserService { ServerResponse<User> login(String username, String password); ServerResponse<String> register(User user); ServerResponse<String> checkValid(String str,String type); ServerResponse selectQuestion(String username); ServerResponse<String> checkAnswer(String username,String question,String answer); ServerResponse<String> forgetResetPassword(String username,String passwordNew,String forgetToken); ServerResponse<String> resetPassword(String passwordOld,String passwordNew,User user); ServerResponse<User> updateInformation(User user); ServerResponse<User> getInformation(Integer userId); } @Service("iUserService") public class UserServiceImpl implements IUserService { @Autowired private UserMapper userMapper; @Override public ServerResponse<User> login(String username, String password) { int resultCount=userMapper.checkUserName(username); if(resultCount==0){ return ServerResponse.createByErrorMessage("用户名不存在"); } //todo 密码登录MD5 String md5Password=MD5Util.MD5EncodeUtf8(password); User user=userMapper.selectLogin(username, md5Password); if(username==null){ return ServerResponse.createByErrorMessage("密码错误"); } user.setPassword(org.apache.commons.lang3.StringUtils.EMPTY); return ServerResponse.createBySuccessMessage("登陆成功"); } public ServerResponse<String> register(User user){ ServerResponse validResponse=this.checkValid(user.getUsername(),Const.USERNAME); if(!validResponse.isSuccess()){ return validResponse; } validResponse=this.checkValid(user.getEmail(),Const.EMAIL); if(!validResponse.isSuccess()){ return validResponse; } user.setRole(Const.Role.ROLE_CUSTOMER); //MD5加密 user.setPassword(MD5Util.MD5EncodeUtf8(user.getPassword())); int resultCount=userMapper.insert(user); if(resultCount==0){ return ServerResponse.createByErrorMessage("注册失败"); } return ServerResponse.createBySuccessMessage("注册成功"); } public ServerResponse<String> checkValid(String str,String type){ if(org.apache.commons.lang3.StringUtils.isNotBlank(type)){ //开始校验 if(Const.USERNAME.equals(type)){ int resultCount=userMapper.checkUserName(str); if(resultCount>0){ return ServerResponse.createByErrorMessage("用户名已存在"); } } if(Const.EMAIL.equals(type)){ int resultCount=userMapper.checkEmail(str); if(resultCount>0){ return ServerResponse.createByErrorMessage("email已存在"); } } }else{ ServerResponse.createByErrorMessage("参数错误"); } return ServerResponse.createBySuccessMessage("校验成功"); } public ServerResponse selectQuestion(String username){ ServerResponse validResponse=this.checkValid(username,Const.USERNAME); if(validResponse.isSuccess()){ //用户不存在 return ServerResponse.createByErrorMessage("用户不存在"); } String question=userMapper.selectQuestionByUsername(username); if(StringUtils.isNotBlank(question)){ return ServerResponse.createBySuccess(question); } return ServerResponse.createByErrorMessage("没有相关找回密码问题"); } public ServerResponse<String> checkAnswer(String username,String question,String answer){ int resultCount=userMapper.checkAnswer(username, question, answer); if(resultCount>0){ //说明问题及答案正确 String forgetToken=UUID.randomUUID().toString(); TokenCache.setKey(TokenCache.TOKEN_PREFIX+username,forgetToken); return ServerResponse.createBySuccess(forgetToken); } return ServerResponse.createByErrorMessage("问题的答案错误"); } public ServerResponse<String> forgetResetPassword(String username,String passwordNew,String forgetToken){ if(StringUtils.isBlank(forgetToken)){ return ServerResponse.createByErrorMessage("参数错误,token需要传递"); } ServerResponse validResponse=this.checkValid(username,Const.USERNAME); if(validResponse.isSuccess()){ return ServerResponse.createByErrorMessage("用户不存在"); } String token=TokenCache.getKey(TokenCache.TOKEN_PREFIX+username); if(StringUtils.isBlank(token)){ return ServerResponse.createByErrorMessage("token无效或者已过期"); } if(StringUtils.equals(forgetToken,token)){ String MD5Password = MD5Util.MD5EncodeUtf8(passwordNew); int rowCount=userMapper.updatePasswordByUsername(username,MD5Password); if(rowCount>0){ return ServerResponse.createBySuccessMessage("修改密码成功"); }else { return ServerResponse.createByErrorMessage("token错误,请重新获取"); } } return ServerResponse.createByErrorMessage("修改密码失败"); } public ServerResponse<String> resetPassword(String passwordOld,String passwordNew,User user){ //防止横向越权,要校验一下这个用户的旧密码,一定要指定是这个用户,因为我们会查询一个count(1),如果不指定ID,那么结果就是true count>0 int resultCount=userMapper.checkPassword(MD5Util.MD5EncodeUtf8(passwordOld),user.getId()); if(resultCount==0){ return ServerResponse.createByErrorMessage("旧密码错误"); } user.setPassword(MD5Util.MD5EncodeUtf8(passwordNew)); int updateCount=userMapper.updateByPrimaryKeySelective(user); if(updateCount>0){ return ServerResponse.createBySuccessMessage("密码更新成功"); } return ServerResponse.createByErrorMessage("密码更新失败"); } public ServerResponse<User> updateInformation(User user){ //username是不能被更新的 //email也需要一个校验,不能重复使用 int resultCount=userMapper.checkEmailByUserId(user.getEmail(),user.getId()); if(resultCount>0){ return ServerResponse.createByErrorMessage("email已存在!"); } User updateUser=new User(); updateUser.setId(user.getId()); updateUser.setPhone(user.getPhone()); updateUser.setEmail(user.getEmail()); updateUser.setQuestion((user.getQuestion())); updateUser.setAnswer((user.getAnswer())); int updateCount=userMapper.updateByPrimaryKeySelective(updateUser); if(updateCount>0){ return ServerResponse.createBySuccessMessage("更新个人信息成功"); } return ServerResponse.createByErrorMessage("更新个人信息失败"); } public ServerResponse<User> getInformation(Integer userId){ User user=userMapper.selectByPrimaryKey(userId); if(user==null){ return ServerResponse.createByErrorMessage("找不到当前用户"); } //获取当前用户信息时,把密码显示为空,防止用户隐私泄露 user.setPassword(StringUtils.EMPTY); return ServerResponse.createBySuccess(user); } } //还是这个BeanCreationException,究竟是什么原因呢? //还想问一下老师,老师您给的pom.xml文件是不是不全,我跟着您的步骤做的,发现如LoadingCache, //@JsonIgnore等需要自己再去加一些maven依赖,而且我把<org.mybatis.version>的版本改为了更早 //之前的,要不然就无法使用@param的这个注解,想知道具体的一点原因,谢谢老师!
012018-05-31 -
Geely
2018-05-19
Error creating bean with name 'userMapper' defined in file [C:\apache-tomcat-9.0.5\webapps\mmall\WEB-INF\classes\com\mmall\dao\UserMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory': : Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext-datasource.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext-datasource.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'initialSize'; nested exception is java.lang.NumberFormatException: For input string: "${db.initialSize}"; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext-datasource.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext-datasource.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'initialSize'; nested exception is java.lang.NumberFormatException: For input string: "${db.initialSize}"
你好,同学,我看这个关键异常
可以把db相关的配置发上来,例如这个 is java.lang.NumberFormatException: For input string: "${db.initialSize}";
格式错误,看看你的格式是不是错误了?有些引号么?发上来具体的配置,我们一起看看。
00
相似问题