我比较笨,这个框架整合给我搞得疲惫,还是思路不清晰,走着走着我就一片茫然
配置:
声明:
所有maven引入资源都从https://mvnrepository.com/这里取得。
STEP1:
创建maven web项目:
STEP2:
创建好后,文件夹,package补全:
STEP3:
使用servlet3,并修改web.xml头部信息
1 2 3 <dependency> 4 <groupId>javax.servletgroupId> 5 <artifactId>javax.servlet-apiartifactId> 6 <version>3.1.0version> 7 <scope>providedscope> 8 dependency>
1 xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 4 version="3.0"> 5 <welcome-file-list> 6 <welcome-file>index.jspwelcome-file> 7 welcome-file-list> 8 web-app>
STEP4:
引入最新的spring版本;(5.1.9.RELEASE)
spring-context,spring-core,spring-beans,spring-web,spring-webmvc,spring-test,
STEP5:
创建几个spring配置文件,并配置其中一个
添加一个测试:
将配置文件加入web.xml
1 xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 4 version="3.0"> 5 <welcome-file-list> 6 <welcome-file>index.jspwelcome-file> 7 welcome-file-list> 8 <servlet> 9 <servlet-name>dispatcherServletSpringservlet-name> 10 <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class> 11 <init-param> 12 <param-name>contextConfigLocationparam-name> 13 <param-value>classpath:spring/spring-*.xmlparam-value> 14 init-param> 15 servlet> 16 <servlet-mapping> 17 <servlet-name>dispatcherServletSpringservlet-name> 18 <url-pattern>/url-pattern> 19 servlet-mapping> 20 web-app>
结果:
STEP6:
maven引入mysql-connector-java,spring-jdbc.
书写jdbc.properties
1 jdbc.user=root 2 jdbc.password=123456 3 jdbc.driver=com.mysql.cj.jdbc.Driver 4 jdbc.url=jdbc:mysql:///xyz?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT
引入c3p0,使用人数最多的,0.9.5.2,,,spring-tx,,
引入mybatis,mybatis-spring
已经验证可以用了,有点多,不想写了,这是链接:
1 链接:https://pan.baidu.com/s/1uv5ioiyLybu3tYlp5cEHKw 2 提取码:lt5u 3 复制这段内容后打开百度网盘手机App,操作更方便哦
一般入门问题都在这些包环境上,这是pom.xml,这一套可以通过测试;
1 xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0modelVersion> 5 6 <groupId>sadness.xyzgroupId> 7 <artifactId>website01artifactId> 8 <version>1.0-SNAPSHOTversion> 9 <packaging>warpackaging> 10 11 <name>website01 Maven Webappname> 12 13 <url>http://www.example.comurl> 14 15 <properties> 16 <project.build.sourceEncoding>UTF-8project.build.sourceEncoding> 17 <maven.compiler.source>1.8maven.compiler.source> 18 <maven.compiler.target>1.8maven.compiler.target> 19 properties> 20 21 <dependencies> 22 23 24 <dependency> 25 <groupId>log4jgroupId> 26 <artifactId>log4jartifactId> 27 <version>1.2.17version> 28 dependency> 29 30 <dependency> 31 <groupId>org.slf4jgroupId> 32 <artifactId>slf4j-log4j12artifactId> 33 <version>1.7.25version> 34 <scope>testscope> 35 dependency> 36 37 <dependency> 38 <groupId>org.slf4jgroupId> 39 <artifactId>slf4j-apiartifactId> 40 <version>1.7.25version> 41 dependency> 42 43 <dependency> 44 <groupId>org.slf4jgroupId> 45 <artifactId>slf4j-simpleartifactId> 46 <version>1.7.25version> 47 <scope>testscope> 48 dependency> 49 50 51 52 <dependency> 53 <groupId>com.fasterxml.jackson.coregroupId> 54 <artifactId>jackson-databindartifactId> 55 <version>2.10.0.pr1version> 56 dependency> 57 58 <dependency> 59 <groupId>com.fasterxml.jackson.coregroupId> 60 <artifactId>jackson-coreartifactId> 61 <version>2.10.0.pr1version> 62 dependency> 63 64 <dependency> 65 <groupId>com.fasterxml.jackson.coregroupId> 66 <artifactId>jackson-annotationsartifactId> 67 <version>2.10.0.pr1version> 68 dependency> 69 70 71 72 <dependency> 73 <groupId>org.mybatisgroupId> 74 <artifactId>mybatisartifactId> 75 <version>3.5.2version> 76 dependency> 77 78 <dependency> 79 <groupId>org.mybatisgroupId> 80 <artifactId>mybatis-springartifactId> 81 <version>2.0.2version> 82 dependency> 83 84 85 <dependency> 86 <groupId>com.mchangegroupId> 87 <artifactId>c3p0artifactId> 88 <version>0.9.5.2version> 89 dependency> 90 91 <dependency> 92 <groupId>org.springframeworkgroupId> 93 <artifactId>spring-txartifactId> 94 <version>5.1.9.RELEASEversion> 95 dependency> 96 97 98 <dependency> 99 <groupId>mysqlgroupId> 100 <artifactId>mysql-connector-javaartifactId> 101 <version>8.0.17version> 102 dependency> 103 104 105 106 <dependency> 107 <groupId>org.springframeworkgroupId> 108 <artifactId>spring-contextartifactId> 109 <version>5.1.9.RELEASEversion> 110 dependency> 111 112 <dependency> 113 <groupId>org.springframeworkgroupId> 114 <artifactId>spring-coreartifactId> 115 <version>5.1.9.RELEASEversion> 116 dependency> 117 118 <dependency> 119 <groupId>org.springframeworkgroupId> 120 <artifactId>spring-beansartifactId> 121 <version>5.1.9.RELEASEversion> 122 dependency> 123 124 <dependency> 125 <groupId>org.springframeworkgroupId> 126 <artifactId>spring-webartifactId> 127 <version>5.1.9.RELEASEversion> 128 dependency> 129 130 <dependency> 131 <groupId>org.springframeworkgroupId> 132 <artifactId>spring-webmvcartifactId> 133 <version>5.1.9.RELEASEversion> 134 dependency> 135 136 <dependency> 137 <groupId>org.springframeworkgroupId> 138 <artifactId>spring-testartifactId> 139 <version>5.1.9.RELEASEversion> 140 <scope>testscope> 141 dependency> 142 143 <dependency> 144 <groupId>org.springframeworkgroupId> 145 <artifactId>spring-jdbcartifactId> 146 <version>5.1.9.RELEASEversion> 147 dependency> 148 149 150 151 152 <dependency> 153 <groupId>javax.servletgroupId> 154 <artifactId>javax.servlet-apiartifactId> 155 <version>3.1.0version> 156 <scope>providedscope> 157 dependency> 158 159 <dependency> 160 <groupId>junitgroupId> 161 <artifactId>junitartifactId> 162 <version>4.12version> 163 <scope>testscope> 164 dependency> 165 dependencies> 166 167 <build> 168 <finalName>website01finalName> 169 <pluginManagement> 170 <plugins> 171 <plugin> 172 <artifactId>maven-clean-pluginartifactId> 173 <version>3.1.0version> 174 plugin> 175 176 <plugin> 177 <artifactId>maven-resources-pluginartifactId> 178 <version>3.0.2version> 179 plugin> 180 <plugin> 181 <artifactId>maven-compiler-pluginartifactId> 182 <version>3.8.0version> 183 plugin> 184 <plugin> 185 <artifactId>maven-surefire-pluginartifactId> 186 <version>2.22.1version> 187 plugin> 188 <plugin> 189 <artifactId>maven-war-pluginartifactId> 190 <version>3.2.2version> 191 plugin> 192 <plugin> 193 <artifactId>maven-install-pluginartifactId> 194 <version>2.5.2version> 195 plugin> 196 <plugin> 197 <artifactId>maven-deploy-pluginartifactId> 198 <version>2.8.2version> 199 plugin> 200 plugins> 201 pluginManagement> 202 build> 203 project>