欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Intellij IDEA 2019 + Java Spring MVC + Hibernate学习笔记(1)

程序员文章站 2022-06-05 20:21:36
之前的技术栈一直是围绕.net 做的,现在.net 技术栈的使用越来越少,越来越窄。好多原来的同事都转Java开发了。 最近公司变动,自己需要重新找个坑,压力山大。好多要求Java技术栈的根本没机会进,自己的那点Java功底,之前做过混合开发的Java插件,Web项目10多年没碰了... 好在几个原 ......

之前的技术栈一直是围绕.net 做的,现在.net 技术栈的使用越来越少,越来越窄。好多原来的同事都转java开发了。

最近公司变动,自己需要重新找个坑,压力山大。好多要求java技术栈的根本没机会进,自己的那点java功底,之前做过混合开发的java插件,web项目10多年没碰了...

好在几个原来的同事都是所在公司的骨干,java也用的很溜,嗯,向人家学习吧。。。

先把相关的家伙事准备好。

Intellij IDEA 2019 + Java Spring MVC + Hibernate学习笔记(1)

该安装的安装,改配置的配置。

开始架构第一个项目。点菜单file->new->project。打开new project窗口。左边选spring,右边选择spring mvc。

Intellij IDEA 2019 + Java Spring MVC + Hibernate学习笔记(1)

拉到下边选择hibernate和sql support,数据库支持选择mysql

Intellij IDEA 2019 + Java Spring MVC + Hibernate学习笔记(1)

点击下边next,给项目一个名字,javastudy。设置项目存放目录。设置完成后点击下边的按钮finish。然后开始自动下载所依赖的相关包。

很快下载完成,第一个项目基本轮廓就有了。

选中web目录下的index.jsp然后点击菜单run->run 'index.jsp',开始第一次运行。。。

[2019-07-21 12:23:40,433] artifact javastudy:war exploded: artifact is being deployed, please wait...
21-jul-2019 12:23:40.672 警告 [rmi tcp connection(2)-127.0.0.1] org.apache.tomcat.util.descriptor.web.webxml.setversion unknown version string [4.0]. default version will be used.
21-jul-2019 12:23:40.786 严重 [rmi tcp connection(2)-127.0.0.1] org.apache.catalina.core.standardcontext.startinternal one or more listeners failed to start. full details will be found in the appropriate container log file
21-jul-2019 12:23:40.788 严重 [rmi tcp connection(2)-127.0.0.1] org.apache.catalina.core.standardcontext.startinternal context [/javastudy_war_exploded] startup failed due to previous errors
[2019-07-21 12:23:40,804] artifact javastudy:war exploded: error during artifact deployment. see server log for details.

第一次运行果然会掉进坑里...。各种搜索,然后做了下边的操作。在web->web-inf目录下新建一个classes目录。然后建一个logging.properties文件。

Intellij IDEA 2019 + Java Spring MVC + Hibernate学习笔记(1)

logging.properties文件内容如下:

handlers = org.apache.juli.filehandler, java.util.logging.consolehandler    

############################################################
# handler specific properties.
# describes specific configuration info for handlers.
############################################################

org.apache.juli.filehandler.level = fine    
org.apache.juli.filehandler.directory = ../logs    
org.apache.juli.filehandler.prefix = error-debug.    

java.util.logging.consolehandler.level = fine    
java.util.logging.consolehandler.formatter = java.util.logging.simpleformatter

这样运行后控制台就可以显示具体的错误。否则只显示出错,不显示具体内容,再次运行,

严重: error configuring application listener of class [org.springframework.web.context.contextloaderlistener]
java.lang.classnotfoundexception: org.springframework.web.context.contextloaderlistener
    at org.apache.catalina.loader.webappclassloaderbase.loadclass(webappclassloaderbase.java:1360)
    at org.apache.catalina.loader.webappclassloaderbase.loadclass(webappclassloaderbase.java:1182)
    at org.apache.catalina.core.defaultinstancemanager.loadclass(defaultinstancemanager.java:546)
    at org.apache.catalina.core.defaultinstancemanager.loadclassmaybeprivileged(defaultinstancemanager.java:527)
    at org.apache.catalina.core.defaultinstancemanager.newinstance(defaultinstancemanager.java:150)
    at org.apache.catalina.core.standardcontext.listenerstart(standardcontext.java:4621)
    at org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5165)
    at org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150)
    at org.apache.catalina.core.containerbase.addchildinternal(containerbase.java:743)
    at org.apache.catalina.core.containerbase.addchild(containerbase.java:719)
    at org.apache.catalina.core.standardhost.addchild(standardhost.java:714)
    at org.apache.catalina.startup.hostconfig.manageapp(hostconfig.java:1720)
    at sun.reflect.nativemethodaccessorimpl.invoke0(native method)
[2019-07-21 12:28:31,020] artifact javastudy:war exploded: error during artifact deployment. see server log for details.
    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 org.apache.catalina.mbeans.mbeanfactory.createstandardcontext(mbeanfactory.java:483)
    at org.apache.catalina.mbeans.mbeanfactory.createstandardcontext(mbeanfactory.java:432)
    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 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 com.sun.jmx.remote.security.mbeanserveraccesscontroller.invoke(mbeanserveraccesscontroller.java:468)
    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 java.security.accesscontroller.doprivileged(native method)
    at javax.management.remote.rmi.rmiconnectionimpl.doprivilegedoperation(rmiconnectionimpl.java:1408)
    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:357)
    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:573)
    at sun.rmi.transport.tcp.tcptransport$connectionhandler.run0(tcptransport.java:834)
    at sun.rmi.transport.tcp.tcptransport$connectionhandler.lambda$run$0(tcptransport.java:688)
    at java.security.accesscontroller.doprivileged(native method)
    at sun.rmi.transport.tcp.tcptransport$connectionhandler.run(tcptransport.java:687)
    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)
java.lang.classnotfoundexception,这应该是没有找到这个包。新创建的项目按道理说不应该啊。选中项目,然后按f4,打开project structure窗口。
在project settings找到了artifacts中找到了一些问题提示。项目输出结构貌似有问题。依赖包找不到
Intellij IDEA 2019 + Java Spring MVC + Hibernate学习笔记(1)

点击下边的fix按钮,选择add all missing 。。。

Intellij IDEA 2019 + Java Spring MVC + Hibernate学习笔记(1)

三个缺失的依赖库被自动添加了

Intellij IDEA 2019 + Java Spring MVC + Hibernate学习笔记(1)

点击ok,再次运行...,

浏览器打开了,这是要成功的节奏啊。期待hello world...

Intellij IDEA 2019 + Java Spring MVC + Hibernate学习笔记(1)

404是几个意思?

又掉坑里了...

用idea+tomcat + 404做关键字,搜索后找到了类似的问题,

run->edit configuration,打开run/debug configurations,选中tomcate server下的index.jsp,右边选择deployment选项卡,然后把application context 下的内容改成“/”,点击按钮ok

Intellij IDEA 2019 + Java Spring MVC + Hibernate学习笔记(1)

再次运行。。。

Intellij IDEA 2019 + Java Spring MVC + Hibernate学习笔记(1)

终于出来了