Skip to content

Commit 95e8112

Browse files
micro service
1 parent 034bc03 commit 95e8112

50 files changed

Lines changed: 2234 additions & 13 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

notes/微服务/微服务.md

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ docker pull 镜像名字:版本号
130130

131131

132132

133-
134-
135133
给docker加速:
136134

137135
(1)通过加速网站
@@ -166,14 +164,8 @@ docker ps -a
166164

167165
docker run -di --name=micro_mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root123 daocloud.io/library/mysql:5.5.61
168166

169-
170-
171-
172-
173167
docker ps -a
174168

175-
176-
177169
启动mysql:
178170

179171
docker start 2b9f9ca5c2be
@@ -194,8 +186,6 @@ docker rm 2b9f9ca5c2be
194186

195187

196188

197-
198-
199189
测试工具:
200190

201191
postman
@@ -208,8 +198,6 @@ mapper接口前的@Mapper 和@MapperScan(value="com.yanqun.micro_city.mapper")
208198

209199

210200

211-
212-
213201
在使用maven时,如果a依赖了b项目,但是无法import b中的api,解决方案:先将 b进行install,然后再import
214202

215203

@@ -251,7 +239,83 @@ mapper接口前的@Mapper 和@MapperScan(value="com.yanqun.micro_city.mapper")
251239

252240
增加了一些注解 和一些配置。
253241

254-
spring boot自动装配,帮我们配置一些东西 。 如果某些自动装配失效,那么可以尝试手工装配。
242+
spring boot自动装配,帮我们配置一些东西 。 如果某些自动装配失效,那么可以尝试手工装配。
243+
244+
245+
246+
- micro_city:springboot+ssm +注解
247+
- micro_city2:springboot+ssm +SQL映射文件
248+
- micro_city3: springboot+ssm + 外部配置文件/配置类
249+
250+
251+
252+
micro_city3、micro_city4:不适用springboot的部分自动装配功能;而使用我们自定义的 配置文件、配置类
253+
254+
(1)外部配置文件:micro_city3
255+
256+
重点:要引入外部配置文件,需要在springboot入口类上加注解:
257+
258+
```java
259+
@ImportResource(locations={"classpath:applicationContext.xml"})
260+
@SpringBootApplication
261+
public class MicroCityApplication {
262+
263+
public static void main(String[] args) {
264+
SpringApplication.run(MicroCityApplication.class, args);
265+
}
266+
267+
}
268+
```
269+
270+
问题总结:
271+
272+
1.springboot启动时,必须有 appication.properties/yaml
273+
274+
2.如果创建的是spring boot项目,项目在创建时会自动 创建一个入口类、测试类;我们直接在测试类中写方法即可。但是,如果是手工自己编写的测试类,并且这个测试类 和入口类 没有遵循maven约定,则需要 手工给测试类 指定 要测试的是哪个类。
275+
276+
```java
277+
278+
@SpringBootTest(classes = MicroCityApplication.class)
279+
@RunWith(SpringRunner.class)
280+
public class MiCro_CIty3_Test {
281+
...
282+
}
283+
```
284+
285+
286+
287+
288+
289+
(2)配置类:micro_city4
290+
291+
```java
292+
package micro_city4;
293+
294+
import micro_city4.dao.CityDao;
295+
import micro_city4.entity.City;
296+
import micro_city4.service.CityService;
297+
import org.springframework.context.annotation.Bean;
298+
import org.springframework.context.annotation.Configuration;
299+
300+
/*
301+
* Created by 颜群
302+
*/
303+
@Configuration
304+
public class MyConfiguration {//配置类
305+
306+
@Bean
307+
public CityService cityService(){
308+
CityService cityService = new CityService();
309+
CityDao cityDao = new CityDao();
310+
cityService.setCityDao( cityDao );
311+
return cityService ;
312+
}
313+
}
314+
315+
316+
```
317+
318+
说明:配置类 由于会在启动时被@SpringBootApplication扫描,因此 无需再家 @importReource...
255319

256320

257321

sources/microservice/.idea/compiler.xml

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sources/microservice/.idea/encodings.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sources/microservice/.idea/misc.xml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sources/microservice/.idea/uiDesigner.xml

Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)