您的位置:首页 > 编程语言 > Java开发

javaweb开发中的那些坑

2016-12-27 19:34 197 查看
最近电脑有点问题,没办法就重装系统了,花了一个晚上重装IDE、,配置环境,好不容易把eclipse的环境弄好,加载之前的项目时却又到各种问题,一怒之下,写一篇记录下在javaweb开发中遇到的各种坑

一、Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/asaad]]

在重新配置tomcat的时候会遇到这种情况,一般报错如下:
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8006]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.startup.Catalina.start(Catalina.java:625)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:4)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:769)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:441)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 9 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:924)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
下面是具体的解决方案:
1、右击web工程-》属性或Build Path-》Java Build Path->Libraries-> Add Libray...->Server Runtime -》Tomcat Server
2、切换到Java Build Path界面中的Orader and Export,选择Tomcat。

注意:
按以上方法操作时,若打开Server Runtime后一片空白,需要设置Apache服务器。设置方法为:window->Preferences->Server->Runtime Environment -> add --> 选择Apache的版本后点Next,再填入你apache服务器软件的安装(解压后)地址。

二、Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener java.lang.IllegalArgumentException

报错:

Exception thrown from LifecycleProcessor on context close
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: Root WebApplicationContext: startup date [Tue Dec 27 21:06:21 CST 2016]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:360)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1057)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1010)
at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:549)
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:143)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4859)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5478)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@414bb830: defining beans [admin,advice,business,code,comment,day,job,jobInter,jobType,orders,page,user,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,businessServiceImpl,commentServiceImpl,jobServiceImpl,ordersServiceImpl,userServiceImpl,dataSource,log-filter,sqlSessionFactory,org.mybatis.spring.mapper.MapperScannerConfigurer#0,gson,transactionManager,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor];
root of factory hierarchy

出现这类报错,一般是spring版本与当前jdk版本不兼容造成的,笔者装的是jdk1.8 ,spring是3.2的,所以报错了。解决方案是:更新 Spring-Core
到 4.0.(貌似3.2.16 也可以~~)以上或者将jdk降到1.7即可,传送门~~stack一哥们的解决方案

三、mysql远程连接失败

Mysql为了安全性,在默认情况下用户只允许在本地登录,但有时候还是需要远程连接,解决办法:

1、允许root用户在任何地方进行远程登录,并具有所有库任何操作权限,

具体操作如下:

在本机先使用root用户登录mysql: mysql -u root -p"youpassword" 
进行授权操作:
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;

重载授权表:
FLUSH PRIVILEGES;
即可。但不建议这样操作,因为这样任何人都可能登陆

2、允许root用户在一个特定的IP进行远程登录,并具有所有库任何操作权限,具体操作如下:

 在本机先使用root用户登录mysql: mysql -u root -p"youpassword" 进行授权操作: GRANT ALL PRIVILEGES ON *.* TO root@"172.16.16.152" IDENTIFIED BY "youpassword"
WITH GRANT OPTION; 重载授权表: FLUSH PRIVILEGES; 退出mysql数据库: exit

3、删除用户授权:

需要使用REVOKE命令,具体命令格式为: REVOKE privileges ON 数据库[.表名] FROM user-name; 具体实例,先在本机登录mysql: mysql -u root -p"youpassword" 进行授权操作: GRANT select,insert,update,delete
ON TEST-DB TO test-user@"172.16.16.152" IDENTIFIED BY "youpassword"; 再进行删除授权操作: REVOKE all on TEST-DB from test-user; ****注:该操作只是清除了用户对于TEST-DB的相关授权权限,但是这个“test-user”这个用户还是存在。 最后从用户表内清除用户: DELETE FROM user WHERE user="test-user"; 重载授权表: FLUSH PRIVILEGES; 退出mysql数据库:
exit

4、MYSQL权限详细分类: 

全局管理权限: FILE: 在MySQL服务器上读写文件。 PROCESS: 显示或杀死属于其它用户的服务线程。 RELOAD: 重载访问控制表,刷新日志等。 SHUTDOWN: 关闭MySQL服务。 数据库/数据表/数据列权限: ALTER: 修改已存在的数据表(例如增加/删除列)和索引。
CREATE: 建立新的数据库或数据表。 DELETE: 删除表的记录。 DROP: 删除数据表或数据库。 INDEX: 建立或删除索引。 INSERT: 增加表的记录。 SELECT: 显示/搜索表的记录。 UPDATE: 修改表中已存在的记录。 特别的权限: ALL: 允许做任何事(和root一样)。 USAGE: 只允许登录--其它什么也不允许做。

四、云服务器不能通过80端口访问

看看你的防火墙有没有开着,把它关掉。笔者是用腾讯云服务器的,在腾讯云的后台控制中心,选择默认全放通的安全组,选择了注意要强化下服务器密码。如果还不行,检查是否安装了IIS?
如果安装了IIS角色,请先停止IIS服务.,或者直接删除掉。实在不行就通过netstat -ano|findstr 80找到80端口的PID ,然后到任务管理器把这个PID杀了。

持续更新~~~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: