{"id":588,"date":"2023-03-23T21:28:47","date_gmt":"2023-03-23T13:28:47","guid":{"rendered":""},"modified":"2023-03-23T21:28:47","modified_gmt":"2023-03-23T13:28:47","slug":"SpringBoot \u81ea\u52a8\u88c5\u914d","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/588.html","title":{"rendered":"SpringBoot \u81ea\u52a8\u88c5\u914d"},"content":{"rendered":"


\n <\/head>
\n <\/p>\n

\n

SpringBoot \u81ea\u52a8\u88c5\u914d<\/h1>\n<\/p><\/div>\n
\n SpringBoot\u81ea\u52a8\u914d\u7f6e\u6839\u636e\u6211\u4eec\u6dfb\u52a0\u7684jar\u4f9d\u8d56\u9879\u81ea\u52a8\u914d\u7f6eSpringBoot\u5e94\u7528\u7a0b\u5e8f\u3002\n <\/div>\n
\n \u4f8b\u5982\uff0c\u5982\u679c\u7c7b\u8def\u5f84\u4e2d\u5b58\u5728H2\u6570\u636e\u5e93Jar\uff0c\u800c\u6211\u4eec\u5c1a\u672a\u624b\u52a8\u914d\u7f6e\u4efb\u4f55\u4e0e\u6570\u636e\u5e93\u76f8\u5173\u7684bean\uff0c\u5219Spring Boot\u7684\u81ea\u52a8\u914d\u7f6e\u529f\u80fd\u4f1a\u5728\u9879\u76ee\u4e2d\u81ea\u52a8\u5bf9\u5176\u8fdb\u884c\u914d\u7f6e\u3002\n <\/div>\n
\n \u6211\u4eec\u53ef\u4ee5\u542f\u7528\u81ea\u52a8\u901a\u8fc7\u4f7f\u7528\u6ce8\u89e3
\n @EnableAutoConfiguration <\/strong>\u914d\u7f6e\u529f\u80fd\u3002\u4f46\u662f\u6b64\u6ce8\u89e3\u4e0d\u4f7f\u7528\uff0c\u56e0\u4e3a\u5b83\u5305\u88c5\u5728
\n @SpringBootApplication <\/strong>\u6ce8\u89e3\u5185\u3002\u6ce8\u89e3@SpringBootApplication\u662f\u4e09\u4e2a\u6ce8\u89e3\u7684\u7ec4\u5408:
\n @ComponentScan\uff0c@EnableAutoConfiguration\uff0c<\/strong>\u548c
\n @Configuration <\/strong>\u3002\u4f46\u662f\uff0c\u6211\u4eec\u4f7f\u7528@SpringBootApplication\u6279\u6ce8\u800c\u4e0d\u662f\u4f7f\u7528@EnableAutoConfiguration\u3002\n <\/div>\n
\n @SpringBootApplication = @ComponentScan + @EnableAutoConfiguration + @Configuration <\/strong>\n <\/div>\n
\n \u5f53\u6dfb\u52a0
\n \u5728\u9879\u76ee\u4e2d\u4f7f\u7528spring-boot-starter-web <\/strong>\u4f9d\u8d56\u9879\u65f6\uff0cSpring Boot\u81ea\u52a8\u914d\u7f6e\u4f1a\u5728\u7c7b\u8def\u5f84\u4e2d\u67e5\u627eSpring MVC\u3002\u5b83\u4f1a\u81ea\u52a8\u914d\u7f6e
\n dispatcherServlet <\/strong>\uff0c\u9ed8\u8ba4\u7684
\n \u9519\u8bef\u9875\u9762<\/strong>\u548c
\n \u7f51\u7edc\u7f50\u5b50<\/strong>\u3002\n <\/div>\n
\n \u7c7b\u4f3c\u5730\uff0c\u5f53\u6211\u4eec\u6dfb\u52a0spring-boot-starter-data-jpa \u4f9d\u8d56\u5173\u7cfb\uff0c\u6211\u4eec\u770b\u5230Spring Boot\u81ea\u52a8\u914d\u7f6e\u4f1a\u81ea\u52a8\u914d\u7f6e
\n \u6570\u636e\u6e90<\/strong>\u548c
\n \u5b9e\u4f53\u7ba1\u7406\u5668<\/strong>\u3002\n <\/div>\n
\n \u6240\u6709\u81ea\u52a8\u914d\u7f6e\u903b\u8f91\u90fd\u5728
\n spring-boot-autoconfigure.jar <\/strong>\u4e2d\u5b9e\u73b0\uff0c\u5982\u4e0b\u56fe\u6240\u793a\u3002\n <\/div>\n

SpringBoot \u81ea\u52a8\u88c5\u914d_https:\/\/bianchenghao6.com_\u3010SpringBoot \u6559\u7a0b\u3011_\u7b2c1\u5f20 <\/p>\n

\u9700\u8981\u81ea\u52a8\u914d\u7f6e<\/h2>\n
\n \u57fa\u4e8eSpring\u7684\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u5f88\u591a\u914d\u7f6e\u3002\u4f7f\u7528Spring MVC\u65f6\uff0c\u6211\u4eec\u9700\u8981\u914d\u7f6e
\n dispatcher servlet\uff0c\u89c6\u56fe\u89e3\u6790\u5668\uff0cWeb jars <\/strong>\u3002\u4ee5\u4e0b\u4ee3\u7801\u663e\u793a\u4e86Web\u5e94\u7528\u7a0b\u5e8f\u4e2d\u8c03\u5ea6\u7a0b\u5e8fservlet\u7684\u5178\u578b\u914d\u7f6e:\n <\/div>\n
\n
\r\n<servlet>\r\n<servlet-name>dispatcher<\/servlet-name>\r\n<servlet-class>\r\norg.springframework.web.servlet.DispatcherServlet\r\n<\/servlet-class>\r\n<init-param>\r\n<param-name>contextConfigLocation<\/param-name>\r\n<param-value>\/WEB-INF\/todo-servlet.xml<\/param-value>\r\n<\/init-param>\r\n<load-on-startup>1<\/load-on-startup>\r\n<\/servlet>\r\n<servlet-mapping>\r\n<servlet-name>dispatcher<\/servlet-name>\r\n<url-pattern>\/<\/url-pattern>\r\n<\/servlet-mapping>\r\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u7c7b\u4f3c\u5730\uff0c\u5f53\u6211\u4eec\u4f7f\u7528Hibernate\/JPA\u65f6\uff0c\u6211\u4eec\u9700\u8981\u914d\u7f6e\u6570\u636e\u6e90\uff0c\u4e8b\u52a1\u7ba1\u7406\u5668\uff0c\u5b9e\u4f53\u7ba1\u7406\u5668\u5de5\u5382\u7b49\u7b49\u3002\n <\/div>\n
\n \u914d\u7f6e\u6570\u636e\u6e90<\/strong>\n <\/div>\n
\n
\r\n<bean id=\"dataSource\"<\/span><\/span> class=\"com.mchange.v2.c3p0.ComboPooledDataSource\"<\/span>\r\ndestroy-method=\"close\"<\/span>>\r\n<property name=\"driverClass\"<\/span> value=\"${db.driver}\"<\/span> \/>\r\n<property name=\"jdbcUrl\"<\/span> value=\"${db.url}\"<\/span> \/>\r\n<property name=\"user\"<\/span> value=\"${db.username}\"<\/span> \/>\r\n<property name=\"password\"<\/span> value=\"${db.password}\"<\/span> \/>\r\n<\/bean>\r\n<jdbc:initialize-database data-source=\"dataSource\">\r\n<jdbc:script location=\"classpath:config\/schema.sql\"<\/span> \/>\r\n<jdbc:script location=\"classpath:config\/data.sql\"<\/span> \/>\r\n<\/jdbc:initialize-database>\r\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u914d\u7f6e\u5b9e\u4f53\u7ba1\u7406\u5668\u5de5\u5382<\/strong>\n <\/div>\n
\n
\r\n<bean\r\nclass=\"org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean\"<\/span>\r\nid=\"entityManagerFactory\"<\/span>>\r\n<property name=\"persistenceUnitName\"<\/span> value=\"hsql_pu\"<\/span> \/>\r\n<property name=\"dataSource\"<\/span><\/span> ref=\"dataSource\" \/>\r\n<\/bean>\r\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u914d\u7f6e\u4e8b\u52a1\u7ba1\u7406\u5668<\/strong>\n <\/div>\n
\n
\r\n<bean id=\"transactionManager\"<\/span><\/span> class=\"org.springframework.orm.jpa.JpaTransactionManager\"<\/span>>\r\n<property name=\"entityManagerFactory\"<\/span><\/span> ref=\"entityManagerFactory\" \/>\r\n<property name=\"dataSource\"<\/span><\/span> ref=\"dataSource\" \/>\r\n<\/bean>\r\n<tx:annotation-driven transaction-manager=\"transactionManager\"\/>\r\n<\/pre>\n

<\/code>\n <\/div>\n

\u7981\u7528\u81ea\u52a8\u914d\u7f6e\u7c7b<\/h2>\n
\n \u5982\u679c\u6211\u4eec\u4e0d\u60f3\u88ab\u5e94\u7528\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u7981\u7528\u7279\u5b9a\u7684\u81ea\u52a8\u914d\u7f6e\u7c7b\u3002\u6211\u4eec\u4f7f\u7528\u6ce8\u89e3@EnableAutoConfiguration\u7684
\n exclude <\/strong>\u5c5e\u6027\u6765\u7981\u7528\u81ea\u52a8\u914d\u7f6e\u7c7b\u3002\u4f8b\u5982:\n <\/div>\n
\n
\r\nimport org.springframework.boot.autoconfigure.*;\r\nimport org.springframework.boot.autoconfigure.jdbc.*;\r\nimport org.springframework.context.annotation.*;\r\n@Configuration(proxyBeanMethods = false<\/span>)\r\n@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})\r\npublic <\/span>class <\/span>MyConfiguration \r\n{\r\n}\r\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u5982\u679c\u7c7b\u4e0d\u5728\u7c7b\u8def\u5f84\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528@EnableAutoConfiguration\u6279\u6ce8\u7684\u5c5e\u6027
\n excludeName <\/strong>\u5e76\u6307\u5b9a\u7c7b\u7684
\n qualified <\/strong>\u540d\u79f0\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5c5e\u6027
\n spring.autoconfigure.exclude <\/strong>\u6392\u9664\u4efb\u4f55\u6570\u91cf\u7684\u81ea\u52a8\u914d\u7f6e\u7c7b\u3002\n <\/div>\n

Spring Boot\u81ea\u52a8\u914d\u7f6e\u793a\u4f8b<\/h3>\n
\n \u5728\u4ee5\u4e0b\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u770b\u5230Spring Boot\u7684\u81ea\u52a8\u914d\u7f6e\u529f\u80fd\u5982\u4f55\u5de5\u4f5c\u3002\n <\/div>\n
\n \u6b65\u9aa41: <\/strong>\u6253\u5f00spring Initializr https:\/\/start.spring.io\/\u3002\n <\/div>\n
\n \u7b2c2\u6b65: <\/strong>
\n \u7ec4<\/strong>\u540d\u79f0\u3002\u6211\u4eec\u63d0\u4f9b\u4e86
\n com.lidihuo <\/strong>\u3002\n <\/div>\n
\n \u6b65\u9aa43: <\/strong>\u63d0\u4f9b
\n \u5de5\u4ef6<\/strong> ID\u3002\u6211\u4eec\u63d0\u4f9b\u4e86
\n spring-boot-autoconfiguration-example <\/strong>\u3002\n <\/div>\n
\n \u6b65\u9aa44: <\/strong>\u6dfb\u52a0\u4f9d\u8d56\u9879:
\n Spring Web\uff0cSpring Data JPA\uff0c<\/strong>\u4e00\u4e2a
\n H2\u6570\u636e\u5e93<\/strong>\u3002\n <\/div>\n
\n \u6b65\u9aa45: <\/strong>\u5355\u51fb
\n Generate <\/strong>(\u751f\u6210)\u6309\u94ae\u3002\u5f53\u6211\u4eec\u5355\u51fb\"\u751f\u6210\"\u6309\u94ae\u65f6\uff0c\u5b83\u4f1a\u5c06\u9879\u76ee\u5305\u88c5\u5728
\n Jar <\/strong>\u6587\u4ef6\u4e2d\uff0c\u5e76\u5c06\u5176\u4e0b\u8f7d\u5230\u672c\u5730\u7cfb\u7edf\u3002\n <\/div>\n

SpringBoot \u81ea\u52a8\u88c5\u914d_https:\/\/bianchenghao6.com_\u3010SpringBoot \u6559\u7a0b\u3011_\u7b2c2\u5f20 <\/p>\n

\n \u7b2c6\u6b65: \u63d0\u53d6<\/strong> Jar\u6587\u4ef6\u5e76\u5c06\u5176\u7c98\u8d34\u5230STS\u5de5\u4f5c\u533a\u4e2d\u3002\n <\/div>\n
\n \u6b65\u9aa47: \u5c06<\/strong>\u9879\u76ee\u6587\u4ef6\u5939\u5bfc\u5165STS\u3002\n <\/div>\n
\n \u6587\u4ef6->\u5bfc\u5165->\u73b0\u6709Maven\u9879\u76ee->\u6d4f\u89c8->\u9009\u62e9\u6587\u4ef6\u5939spring-boot-autoconfiguration-example->\u5b8c\u6210\n <\/div>\n
\n \u5bfc\u5165\u9700\u8981\u4e00\u4e9b\u65f6\u95f4\u3002\n <\/div>\n
\n \u6b65\u9aa48: <\/strong>\u5728\u76ee\u5f55\u4e2d\u521b\u5efa\u540d\u79f0\u4e3a
\n com.lidihuo.controller <\/strong>\u7684\u7a0b\u5e8f\u5305\u3002\u6587\u4ef6\u5939
\n src\/main\/java <\/strong>\u3002\n <\/div>\n
\n \u6b65\u9aa49: <\/strong>\u5728\u5305\u4e2d\u521b\u5efa\u540d\u79f0\u4e3a
\n ControllerDemo <\/strong>\u7684Controller\u7c7b\u3002 strong> com.lidihuo.controller \u3002\n <\/div>\n
\n ControllerDemo.java <\/strong>\n <\/div>\n
\n
\r\npackage <\/span>com.lidihuo.controller;\r\nimport org.springframework.stereotype.Controller;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\n@Controller\r\npublic <\/span>class <\/span>ControllerDemo \r\n{\r\n@RequestMapping(\"\/\"<\/span>)\r\npublic <\/span>String home()\r\n{\r\nreturn <\/span>\"home.jsp\"<\/span>;\r\n}\r\n}\r\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u6b65\u9aa410: <\/strong>\u5728\u6587\u4ef6\u5939
\n src\/main\/java <\/strong>\u4e2d\u521b\u5efa\u53e6\u4e00\u4e2a\u540d\u4e3a
\n com.lidihuo.model <\/strong>\u7684\u5305\u3002 p> <\/p>\n
\n \u6b65\u9aa411: <\/strong>\u5728\u5305
\n com.lidihuo.model <\/strong>\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u79f0\u4e3a
\n User <\/strong>\u7684\u7c7b\u3002\n <\/div>\n
\n User.java <\/strong>\n <\/div>\n
\n
\r\npackage <\/span>com.lidihuo.model;\r\nimport javax.persistence.Entity;\r\nimport javax.persistence.Id;\r\nimport javax.persistence.Table;\r\n@Entity\r\n@Table(name=\"userdata\"<\/span>)\r\npublic <\/span>class <\/span>User \r\n{\r\n@Id\r\nprivate <\/span>int <\/span>id;\r\nprivate <\/span>String username;\r\npublic <\/span>int <\/span>getId() \r\n{\r\nreturn <\/span>id;\r\n}\r\npublic void <\/span>setId(int <\/span>id) \r\n{\r\nthis<\/span>.id = id;\r\n}\r\npublic <\/span>String getUname() \r\n{\r\nreturn <\/span>username;\r\n}\r\npublic void <\/span>setUname(String username) \r\n{\r\nthis<\/span>.username = username;\r\n}\r\n@Override\r\npublic <\/span>String toString() \r\n{\r\nreturn <\/span>\"User [id=\"<\/span> + id + \", uname=\"<\/span> + username + \"]\"<\/span>;\r\n}\r\n}\r\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u73b0\u5728\uff0c\u6211\u4eec\u9700\u8981\u914d\u7f6eH2\u6570\u636e\u5e93\u3002\n <\/div>\n
\n \u6b65\u9aa412: <\/strong>\u6253\u5f00
\n application.properties <\/strong>\u6587\u4ef6\u5e76\u914d\u7f6e\u4ee5\u4e0b\u5185\u5bb9:
\n \u7aef\u53e3\uff0c\u542f\u7528H2\u63a7\u5236\u53f0\uff0c\u6570\u636e\u6e90\uff0c<\/strong>\u548c
\n URL\u3002<\/strong>\n <\/div>\n
\n application.properties <\/strong>\n <\/div>\n
\n
\r\nserver.port=8085\r\nspring.h2.console.enabled=true\r\nspring.datasource.plateform=h2\r\nspring.datasource.url=jdbc:h2:mem:lidihuo\r\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u6b65\u9aa413: <\/strong>\u5728\u6587\u4ef6\u5939
\n src\/main\/resources\u4e2d\u521b\u5efa\u4e00\u4e2a SQL <\/strong>\u6587\u4ef6\u3002 <\/strong>\n <\/div>\n
\n \u53f3\u952e\u5355\u51fbsrc\/main\/resources\u6587\u4ef6\u5939->\u65b0\u5efa->\u6587\u4ef6->\u63d0\u4f9b\u6587\u4ef6\u540d->\u5b8c\u6210\n <\/div>\n
\n \u6211\u4eec\u63d0\u4f9b\u4e86\u6587\u4ef6\u540d
\n data.sql <\/strong>\u5e76\u5c06\u4ee5\u4e0b\u6570\u636e\u63d2\u5165\u5176\u4e2d\u3002\n <\/div>\n
\n data.sql <\/strong>\n <\/div>\n
\n
\r\ninsert into userdata values(101,'Tom'<\/span>);\r\ninsert into userdata values(102,'Andrew'<\/span>);\r\ninsert into userdata values(103,'Tony'<\/span>);\r\ninsert into userdata values(104,'Bob'<\/span>);\r\ninsert into userdata values(105,'Sam'<\/span>);\r\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u6b65\u9aa414: <\/strong>\u5728
\n src <\/strong>\u6587\u4ef6\u5939\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u79f0\u4e3a
\n webapp <\/strong>\u7684\u6587\u4ef6\u5939\u3002\n <\/div>\n
\n \u6b65\u9aa415: <\/strong>\u4f7f\u7528\u6211\u4eec\u5728
\n ControllerDemo <\/strong>\u4e2d\u8fd4\u56de\u7684\u540d\u79f0\u521b\u5efa\u4e00\u4e2aJSP\u6587\u4ef6\u3002\u5728ControllerDemo.java\u4e2d\uff0c\u6211\u4eec\u8fd4\u56de\u4e86
\n home.jsp <\/strong>\u3002\n <\/div>\n
\n home.jsp <\/strong>\n <\/div>\n
\n
\r\n<%@page language=\"java\"<\/span> contentType=\"text\/html; charset=ISO-8859-1\"<\/span>\r\npageEncoding=\"ISO-8859-1\"<\/span><\/span>%>\r\n<!DOCTYPE html>\r\n<html>\r\n<head>\r\n<meta charset=\"ISO-8859-1\">\r\n<title>Insert title here<\/title>\r\n<\/head>\r\n<body>\r\n<form action=\"addUser\"<\/span>>\r\nID :<br \/>\r\n<input type=\"text\"<\/span><\/span> name=\"t1\"<\/span>><br \/>\r\nUser name :<br \/>\r\n<input type=\"text\" name=\"t2\"<\/span>><br \/>\r\n<input type=\"submit\"<\/span> value=\"Add\"<\/span>>\r\n<\/form>\r\n<\/body>\r\n<\/html>\r\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u6b65\u9aa416: <\/strong>\u8fd0\u884c
\n SpringBootAutoconfigurationExampleApplication.java <\/strong>\u6587\u4ef6\u3002\u6211\u4eec\u53ef\u4ee5\u5728\u63a7\u5236\u53f0\u4e2d\u770b\u5230\u6211\u4eec\u7684\u5e94\u7528\u7a0b\u5e8f\u5df2\u6210\u529f\u5728\u7aef\u53e3
\n 8085 <\/strong>\u4e0a\u8fd0\u884c\u3002\n <\/div>\n

SpringBoot \u81ea\u52a8\u88c5\u914d_https:\/\/bianchenghao6.com_\u3010SpringBoot \u6559\u7a0b\u3011_\u7b2c3\u5f20 <\/p>\n

\n \u6b65\u9aa417: <\/strong>\u6253\u5f00\u6d4f\u89c8\u5668\u5e76\u8c03\u7528URL
\n http: \/\/localhost: 8085\/h2-console\/<\/em>\u3002\u5b83\u663e\u793a\u4e86\u6211\u4eec\u5728
\n application.properties <\/strong>\u6587\u4ef6\u4e2d\u914d\u7f6e\u7684
\n \u9a71\u52a8\u7a0b\u5e8f\u7c7b<\/strong>\uff0c
\n JDBC URL <\/strong>\uff0c\u4ee5\u53ca\u9ed8\u8ba4\u7684\u7528\u6237\u540d
\n sa <\/strong>\u3002\n <\/div>\n

SpringBoot \u81ea\u52a8\u88c5\u914d_https:\/\/bianchenghao6.com_\u3010SpringBoot \u6559\u7a0b\u3011_\u7b2c4\u5f20 <\/p>\n

\n \u6211\u4eec\u8fd8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u6d4b\u8bd5\u8fde\u63a5\u70b9\u51fb
\n \u6d4b\u8bd5\u8fde\u63a5<\/strong>\u6309\u94ae\u3002\u5982\u679c\u8fde\u63a5\u6210\u529f\uff0c\u5219\u663e\u793a\u6d88\u606f
\n \u6d4b\u8bd5\u6210\u529f\u3002<\/strong>\n <\/div>\n
\n \u6b65\u9aa418: <\/strong>\u5355\u51fb
\n \u8fde\u63a5<\/strong>\u6309\u94ae\u3002\u5b83\u663e\u793a\u4e86\u6211\u4eec\u5728User.java\u6587\u4ef6\u4e2d\u5b9a\u4e49\u7684\u8868
\n userdata <\/strong>\u7684\u7ed3\u6784\u3002\n <\/div>\n

SpringBoot \u81ea\u52a8\u88c5\u914d_https:\/\/bianchenghao6.com_\u3010SpringBoot \u6559\u7a0b\u3011_\u7b2c5\u5f20 <\/p>\n

\n \u6b65\u9aa419: <\/strong>\u6267\u884c\u4ee5\u4e0b\u67e5\u8be2\uff0c\u4ee5\u67e5\u770b\u6211\u4eec\u5df2\u63d2\u5165
\n data.sql <\/strong>\u6587\u4ef6\u4e2d\u7684\u6570\u636e\n <\/div>\n
\n
\r\nSELECT * FROM USERDATA;\r\n<\/pre>\n

<\/code>\n <\/div>\n

SpringBoot \u81ea\u52a8\u88c5\u914d_https:\/\/bianchenghao6.com_\u3010SpringBoot \u6559\u7a0b\u3011_\u7b2c6\u5f20 <\/p>\n

\n \u8ba9\u6211\u4eec\u4ed4\u7ec6\u770b\u4e00\u4e0b\u63a7\u5236\u53f0\u3002\u6211\u4eec\u770b\u5230
\n TransactionManagement\uff0cDispatcherServlet\uff0cEntityManagerFactory\uff0c<\/strong>\u548c
\n DataSource <\/strong>\u4f1a\u81ea\u52a8\u914d\u7f6e\uff0c\u5982\u4e0b\u56fe\u6240\u793a\u3002\n <\/div>\n

SpringBoot \u81ea\u52a8\u88c5\u914d_https:\/\/bianchenghao6.com_\u3010SpringBoot \u6559\u7a0b\u3011_\u7b2c7\u5f20 <\/p>\n

\u8c03\u8bd5\u81ea\u52a8\u914d\u7f6e<\/h2>\n
\n \u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u627e\u5230\u6709\u5173\u81ea\u52a8\u914d\u7f6e\u7684\u66f4\u591a\u4fe1\u606f: \u4f7f\u7528\u4ee5\u4e0b\u4e24\u79cd\u65b9\u5f0f:\n <\/div>\n

\u6253\u5f00\u8c03\u8bd5\u65e5\u5fd7\u8bb0\u5f55<\/span>
\n \u4f7f\u7528Spring Boot\u6267\u884c\u5668<\/span> <\/p>\n

\n \u6253\u5f00\u8c03\u8bd5\u65e5\u5fd7\u8bb0\u5f55<\/strong>\n <\/div>\n
\n \u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5728
\n application.properties <\/strong>\u4e2d\u6dfb\u52a0\u5c5e\u6027\u6765\u8c03\u8bd5\u65e5\u5fd7\u8bb0\u5f55\u6587\u4ef6\u3002\u8ba9\u6211\u4eec\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\u5b9e\u73b0\u8c03\u8bd5\u65e5\u5fd7\u8bb0\u5f55\u3002\u6253\u5f00
\n application.properties <\/strong>\u6587\u4ef6\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u5c5e\u6027:\n <\/div>\n
\n
\r\nlogging.level.org.springframework: DEBUG\r\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u73b0\u5728\u91cd\u65b0\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\u3002\u6211\u4eec\u770b\u5230\u5728\u65e5\u5fd7\u4e2d\u6253\u5370\u4e86\u4e00\u4e2a\u81ea\u52a8\u914d\u7f6e\u62a5\u544a\u3002\u8be5\u62a5\u544a\u5305\u62ec\u6240\u6709\u81ea\u52a8\u914d\u7f6e\u7684\u7c7b\u3002\u5206\u4e3a\u4e24\u90e8\u5206:
\n \u6b63\u5411\u5339\u914d<\/strong>\u548c
\n \u8d1f\u5411\u5339\u914d<\/strong>\uff0c\u5982\u4e0b\u56fe\u6240\u793a\u3002\n <\/div>\n
\n \u6b63\u5411\u5339\u914d<\/strong>\n <\/div>\n

SpringBoot \u81ea\u52a8\u88c5\u914d_https:\/\/bianchenghao6.com_\u3010SpringBoot \u6559\u7a0b\u3011_\u7b2c8\u5f20 <\/p>\n

\n \u5426\u5b9a\u5339\u914d<\/strong>\n <\/div>\n

SpringBoot \u81ea\u52a8\u88c5\u914d_https:\/\/bianchenghao6.com_\u3010SpringBoot \u6559\u7a0b\u3011_\u7b2c9\u5f20 <\/p>\n

\n Spring Boot\u6267\u884c\u5668<\/strong>\n <\/div>\n
\n \u6211\u4eec\u8fd8\u53ef\u4ee5\u901a\u8fc7\u5728\u9879\u76ee\u4e2d\u4f7f\u7528
\n Actuator <\/strong>\u8c03\u8bd5\u81ea\u52a8\u914d\u7f6e\u3002\u6211\u4eec\u8fd8\u5c06\u6dfb\u52a0
\n HAL\u6d4f\u89c8\u5668<\/strong>\uff0c\u4ee5\u7b80\u5316\u64cd\u4f5c\u3002\n <\/div>\n
\n \u8ba9\u6211\u4eec\u521b\u5efa\u4e00\u4e2aSpring Boot Actuator\u793a\u4f8b\u3002\n <\/div>\n
\n \u6b65\u9aa41: <\/strong>\u6253\u5f00Spring Initializr http:\/\/start.spring.io \u3002\n <\/div>\n
\n \u6b65\u9aa42: <\/strong>\u63d0\u4f9b
\n \u7ec4<\/strong>\u540d\u79f0\u3002\u6211\u4eec\u63d0\u4f9b\u4e86
\n com.lidihuo\u3002<\/strong>\n <\/div>\n
\n \u6b65\u9aa43: <\/strong>\u63d0\u4f9b
\n \u5de5\u4ef6<\/strong> ID\u3002\u6211\u4eec\u63d0\u4f9b\u4e86
\n \u6267\u884c\u5668\u81ea\u52a8\u914d\u7f6e\u793a\u4f8b\u3002<\/strong>\n <\/div>\n
\n \u6b65\u9aa44: <\/strong>\u6dfb\u52a0\u4f9d\u8d56\u9879:
\n Spring Web <\/strong>\u548c
\n Spring Boot Actuator\u3002<\/strong>\n <\/div>\n
\n
\r\n<dependency>\r\n<groupId>org.springframework.boot<\/groupId>\r\n<artifactId>spring-boot-starter-web<\/artifactId>\r\n<\/dependency>\r\n<dependency>\r\n<groupId>org.springframework.boot<\/groupId>\r\n<artifactId>spring-boot-starter-actuator<\/artifactId>\r\n<\/dependency>\r\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u6b65\u9aa45: <\/strong>\u5355\u51fb
\n Generate <\/strong>(\u751f\u6210)\u6309\u94ae\u3002\u5b83\u5c06\u4e0e\u9879\u76ee\u76f8\u5173\u7684\u6240\u6709\u89c4\u8303\u7ed1\u5b9a\u5230\u4e00\u4e2a
\n jar <\/strong>\u6587\u4ef6\u4e2d\uff0c\u5e76\u5c06\u5176\u4e0b\u8f7d\u5230\u6211\u4eec\u7684\u672c\u5730\u7cfb\u7edf\u4e2d\u3002\n <\/div>\n
\n \u6b65\u9aa46: \u63d0\u53d6<\/strong>\u4e0b\u8f7d\u7684jar\u6587\u4ef6\u3002\n <\/div>\n
\n \u6b65\u9aa47: \u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\u5bfc\u5165<\/strong>\u9879\u76ee\u6587\u4ef6\u5939:\n <\/div>\n
\n \u6587\u4ef6->\u5bfc\u5165->\u73b0\u6709Maven\u9879\u76ee->\u4e0b\u4e00\u6b65->\u6d4f\u89c8- >\u9009\u62e9\u9879\u76ee\u6587\u4ef6\u5939->\u5b8c\u6210\n <\/div>\n
\n \u5bfc\u5165\u9879\u76ee\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5728IDE\u7684
\n Package Explorer <\/strong>\u90e8\u5206\u4e2d\u770b\u5230\u4ee5\u4e0b\u76ee\u5f55\u7ed3\u6784\u3002\n <\/div>\n

SpringBoot \u81ea\u52a8\u88c5\u914d_https:\/\/bianchenghao6.com_\u3010SpringBoot \u6559\u7a0b\u3011_\u7b2c10\u5f20 <\/p>\n

\n \u6b65\u9aa48: <\/strong>\u5728\u5305\u4e2d\u521b\u5efaController\u7c7b
\n com.lidihuo\u3002<\/strong>\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a
\n DemoRestController\u7684\u63a7\u5236\u5668\u7c7b\u3002<\/strong>\n <\/div>\n
\n \u5728Controller\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a
\n hello( )<\/strong>\uff0c\u5b83\u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\n <\/div>\n
\n DemoRestController.java <\/strong>\n <\/div>\n
\n
\r\npackage <\/span>com.lidihuo;\r\nimport org.springframework.web.bind.annotation.GetMapping;\r\nimport org.springframework.web.bind.annotation.RestController;\r\n@RestController\r\npublic <\/span>class <\/span>DemoRestController \r\n{\r\n@GetMapping(\"\/hello\"<\/span>)\r\npublic <\/span>String hello() \r\n{\r\nreturn <\/span>\"Hello User, have a nice day.\"<\/span>;\r\n}\r\n}\r\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u6b65\u9aa49: <\/strong>\u8fd0\u884c
\n ActuatorAutoConfigurationExampleApplication.java <\/strong>\u6587\u4ef6\u3002\n <\/div>\n
\n \u6b65\u9aa410: <\/strong>\u6253\u5f00\u6d4f\u89c8\u5668\u5e76\u8c03\u7528URL
\n http: \/\/localhost: 8080\/hello <\/em>\u3002\u5b83\u8fd4\u56de\u6211\u4eec\u5728\u63a7\u5236\u5668\u4e2d\u6307\u5b9a\u7684\u5b57\u7b26\u4e32\u3002\n <\/div>\n

SpringBoot \u81ea\u52a8\u88c5\u914d_https:\/\/bianchenghao6.com_\u3010SpringBoot \u6559\u7a0b\u3011_\u7b2c11\u5f20 <\/p>\n

\n \u73b0\u5728\u8c03\u7528\u6267\u884c\u5668URL
\n http: \/\/localhost: 8080\/actuator <\/em>\u3002\u5b83\u5c06\u542f\u52a8\u663e\u793a\u4ee5\u4e0b\u4e09\u4e2aURL\u7684\u6267\u884c\u5668:
\n self <\/strong>\uff0c
\n health <\/strong>\u548c
\n info <\/strong>\uff0c\u5982\u4e0b\u6240\u793a\u3002\n <\/div>\n
\n
\r\n{\"_links\"<\/span>:{\"self\"<\/span>:{\"href\"<\/span><\/span><\/span><\/span>:\"http:\/\/localhost:8080\/actuator\"<\/span>,\"templated\"<\/span><\/span><\/span><\/span>:false},\"health\"<\/span>:{\"href\":\"http:\/\/localhost:8080\/actuator\/health\"<\/span>,\"templated\":false},\"health-path\"<\/span>:{\"href\":\"http:\/\/localhost:8080\/actuator\/health\/{*path}\"<\/span>,\"templated\":true},\"info\"<\/span>:{\"href\":\"http:\/\/localhost:8080\/actuator\/info\"<\/span>,\"templated\":false}}}\r\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u6b65\u9aa411: <\/strong>\u6253\u5f00
\n pom.xml <\/strong>\u6587\u4ef6\u5e76\u6dfb\u52a0
\n HAL\u6d4f\u89c8\u5668<\/strong>\u4f9d\u8d56\u9879\u3002\n <\/div>\n
\n
\r\n<dependency>\r\n<groupId>org.springframework.data<\/groupId>\r\n<artifactId>spring-data-rest-hal-browser<\/artifactId>\r\n<\/dependency>\r\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u6b65\u9aa412: <\/strong>\u518d\u6b21\uff0c\u8fd0\u884c
\n ActuatorAutoConfigurationExampleApplication.java <\/strong>\u6587\u4ef6\u3002\n <\/div>\n
\n \u8981\u8bbf\u95eeHAL\u6d4f\u89c8\u5668\uff0c\u8bf7\u952e\u5165
\n http:\/\/localhost:8080 <\/em>\u5728\u6d4f\u89c8\u5668\u4e2d\uff0c\u7136\u540e\u6309Enter\u952e\u3002\n <\/div>\n

SpringBoot \u81ea\u52a8\u88c5\u914d_https:\/\/bianchenghao6.com_\u3010SpringBoot \u6559\u7a0b\u3011_\u7b2c12\u5f20 <\/p>\n

\n \u73b0\u5728\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7HAL\u6d4f\u89c8\u5668\u8bbf\u95ee\u6267\u884c\u5668\u3002\n <\/div>\n
\n \u5728\u8d44\u6e90\u7ba1\u7406\u5668\u7684\u6587\u672c\u6846\u4e2d\u952e\u5165
\n \/actuator <\/strong>\uff0c\u7136\u540e\u5355\u51fb
\n Go <\/strong> >\u6309\u94ae\u3002\n <\/div>\n

SpringBoot \u81ea\u52a8\u88c5\u914d_https:\/\/bianchenghao6.com_\u3010SpringBoot \u6559\u7a0b\u3011_\u7b2c13\u5f20 <\/p>\n

\n \u5b83\u663e\u793a\u4e86\u4e0e\u6267\u884c\u5668\u3002\u6267\u884c\u5668\u4e2d\u6700\u91cd\u8981\u7684\u662f
\n beans <\/strong>\u3002\n <\/div>\n

SpringBoot \u81ea\u52a8\u88c5\u914d_https:\/\/bianchenghao6.com_\u3010SpringBoot \u6559\u7a0b\u3011_\u7b2c14\u5f20 <\/p>\n

\n \u5f53\u6211\u4eec\u5355\u51fbbean\u7684\u7bad\u5934\u65f6\uff0c\u5b83\u4f1a\u663e\u793a\u6240\u6709\n <\/div>\n

SpringBoot \u81ea\u52a8\u88c5\u914d_https:\/\/bianchenghao6.com_\u3010SpringBoot \u6559\u7a0b\u3011_\u7b2c15\u5f20 <\/p>\n

\n \u4ee5\u4e0a\u8be5\u56fe\u663e\u793a\u4e86\u6240\u6709\u81ea\u52a8\u914d\u7f6e\u7684
\n beans <\/strong>\u7684\u8be6\u7ec6\u4fe1\u606f\u3002\n <\/div>\n

<\/p>\n


<\/div>\n
\n << Python \u8bed\u6cd5
\n Python \u53d8\u91cf >> \n <\/div>\n

<\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"SpringBoot \u81ea\u52a8\u88c5\u914dzh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[104],"tags":[],"class_list":["post-588","post","type-post","status-publish","format-standard","hentry","category-bc_springboot_jc"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/588"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=588"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/588\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}