对于如下给出的SSM简单的project,如何运行。该项目只有一个Gradle的配置文件和SSM的源文件以及配置文件。
D:\N3verL4nd\Desktop\SSM>tree /f src
卷 本地磁盘 的文件夹 PATH 列表
卷序列号为 00000200 0006:08B0
D:\N3VERL4ND\DESKTOP\SSM\SRC
├─main
│ ├─java
│ │ └─cn
│ │ └─bjut
│ │ ├─controller
│ │ │ PersonController.java
│ │ │
│ │ ├─entity
│ │ │ Person.java
│ │ │
│ │ ├─mapper
│ │ │ PersonMapper.java
│ │ │
│ │ └─service
│ │ │ PersonService.java
│ │ │
│ │ └─impl
│ │ PersonServiceImpl.java
│ │
│ ├─resources
│ │ │ applicationContext.xml
│ │ │ jdbc.properties
│ │ │ log4j.properties
│ │ │ mybatis-config.xml
│ │ │ mybatis-generator.xml
│ │ │ rebel.xml
│ │ │ springmvc.xml
│ │ │
│ │ └─cn
│ │ └─bjut
│ │ └─mapper
│ │ PersonMapper.xml
│ │
│ └─webapp
│ │ index.jsp
│ │
│ └─WEB-INF
│ │ c.tld
│ │ web.xml
│ │
│ └─views
│ hello.jsp
│ test.jsp
│
└─test
├─java
│ T.java
│
└─resources
D:\N3verL4nd\Desktop\SSM>
build.gradle
group 'com.xiya'
version '1.0-SNAPSHOT'
apply plugin: 'idea'
apply plugin: 'war'
sourceCompatibility = 1.8
buildscript {
repositories {
maven {
url 'http://maven.aliyun.com/nexus/content/groups/public/'
}
}
dependencies {
classpath "gradle.plugin.org.akhikhl.gretty:gretty:+"
}
}
apply plugin: "org.akhikhl.gretty"
repositories {
maven {
url 'http://maven.aliyun.com/nexus/content/groups/public/'
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.40'
compile group: 'org.springframework', name: 'spring-context', version: '4.3.9.RELEASE'
compile group: 'org.springframework', name: 'spring-jdbc', version: '4.3.9.RELEASE'
compile group: 'org.springframework', name: 'spring-webmvc', version: '4.3.9.RELEASE'
compile group: 'org.mybatis', name: 'mybatis', version: '3.4.4'
compile group: 'org.mybatis', name: 'mybatis-spring', version: '1.3.1'
compile group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.1.1'
compile group: 'log4j', name: 'log4j', version: '1.2.17'
// providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
providedCompile group: 'javax.servlet', name: 'jstl', version: '1.2'
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
我们使用Gradle生成IDEA环境。-->cmd下执行gradle idea
使用IDEA打开(打开SSM.ipr)
2017/6/17
19:03 Unlinked Gradle project?
Import Gradle project, this will also enable Gradle Tool Window.
Don't want to see the message for the project again: press here.
19:03 Frameworks detected: Web framework is detected in the project Configure
19:03 Spring Configuration Check
Unmapped Spring configuration files found.
Please configure Spring facet or use 'Create Default Context' to add one including all unmapped files.
SSM (2 files) Create Default Context
Show Help Disable...
如上提示,需要配置gradle环境
配置jetty运行下。
E:\t00ls\Merry>curl http://localhost:8080/SSM/
<html>
<head>
<title>Title</title>
</head>
<body>
<a href="/SSM/test1;jsessionid=16o5sh26vkjna1kvjl60vspa78">test</a>
</body>
</html>
E:\t00ls\Merry>
如上配置是能够正确运行的。
但是存在一个提示还没解决:
Intellij IDEA未能找到Spring的配置文件。
这也导致了:
Controller未能识别
未能找到jsp视图文件
加入使用如下方式(Create Default Context),也不能解决该问题。
试验了很多次,找到一个解决方法:
打开Project Structure-->Project Settings-->Moudles
选中XXX_main文件夹,点击上边绿色的加号选择Spring
然后勾选下列选项就可以解决问题了。