活动介绍
file-type

Spring Boot 2.x基础教程:自定义端口和数据库表生成

下载需积分: 9 | 1.03MB | 更新于2025-01-26 | 184 浏览量 | 0 下载量 举报 收藏
download 立即下载
根据提供的文件信息,我们可以挖掘出以下知识点: ### Spring Boot 2.x 示例 #### 知识点一:更改端口号 - **操作方法**:在Spring Boot项目中更改默认端口号是常见的配置需求,以便在一个开发环境中运行多个应用而不冲突。具体操作方法是在项目中的`src/main/resources`目录下的`application.properties`文件中修改`server.port`属性的值。 - **示例代码**: ``` server.port=3132 ``` - **修改位置**:`application.properties`文件是Spring Boot的配置文件之一,用于配置应用的各项属性,如服务器端口、数据库连接信息等。 - **重要性**:掌握如何修改端口号对于进行本地开发、测试或配置多个应用的运行环境非常重要。 #### 知识点二:数据库表的自动生成 - **操作方法**:Spring Boot应用可以通过配置`application.properties`文件中的`spring.jpa.hibernate.ddl-auto`属性来控制数据库表的自动生成行为。这为开发者提供了方便的数据库迁移和模式版本控制功能。 - **示例代码**: ``` spring.jpa.hibernate.ddl-auto=create ``` - **具体行为**:当设置为`create`时,每次应用启动都会根据实体类重新创建数据库表结构。需要注意的是,`create`会导致每次启动应用时数据丢失,实际开发中通常会使用`update`或`validate`。 - **配置属性**:`spring.jpa.hibernate.ddl-auto`是Hibernate提供的用于控制自动创建和更新数据库表结构的配置参数。 #### 知识点三:Spring Boot 2.x 核心技术栈 - **标签覆盖**:给定的标签列表包括了Spring Boot 2.x使用的多个核心技术组件,例如Spring Security、Spring Data、Spring MVC、Thymeleaf、JSP、RabbitMQ、Restful等,以及支持的数据库技术如MongoDB、PostgreSQL和H2。 - **各个组件作用**: - **Spring Security**:提供身份验证和授权机制。 - **Spring Data**:简化数据访问层的开发。 - **Spring MVC**:构建Web层的应用程序。 - **Thymeleaf**:服务端Java模板引擎。 - **JSP**:Java Server Pages,用于构建动态Web页面。 - **RabbitMQ**:消息代理软件,用于消息传递和消息队列。 - **Restful**:开发符合REST原则的网络服务。 - **MongoDB, PostgreSQL, H2**:分别代表了NoSQL数据库、关系型数据库和轻量级内存数据库。 #### 知识点四:项目结构 - **压缩包子文件列表**:提到的`Spring-Boot-2-master`表明这是一个包含主项目文件和资源的压缩包。 - **项目结构**:Spring Boot项目通常包含几个关键的目录结构,包括`src/main/java`(存放Java代码),`src/main/resources`(存放资源文件,如配置文件和静态资源),以及`src/test/java`(存放测试代码)。项目构建完成后,通常还会生成`target`目录(存放编译后的类文件和应用打包文件)。 ### 结论 通过上述知识点,我们可以了解到Spring Boot 2.x在快速开发、项目配置、数据库操作以及对各种技术组件支持等方面的优势。掌握这些知识点对任何使用Spring Boot进行Java开发的开发者来说都是基础且必要的。这些知识点不仅包括了如何进行简单的配置更改,还涉及了使用Spring Boot创建完整的应用程序时需要了解的各种技术组件和工具。

相关推荐

filetype

C:\Users\Administrator\.jdks\ms-17.0.15\bin\java.exe -XX:TieredStopAtLevel=1 -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-Dmanagement.endpoints.jmx.exposure.include=*" "-javaagent:C:\Users\Administrator\AppData\Local\Programs\IntelliJ IDEA Ultimate 2025.1.3\lib\idea_rt.jar=59531" -Dfile.encoding=UTF-8 -classpath C:\Users\Administrator\Desktop\考题示例\考题示例\demo\target\classes;D:\apache-maven-3.9.10\maven-repository\org\springframework\boot\spring-boot-starter-web\3.1.5\spring-boot-starter-web-3.1.5.jar;D:\apache-maven-3.9.10\maven-repository\org\springframework\boot\spring-boot-starter\3.1.5\spring-boot-starter-3.1.5.jar;D:\apache-maven-3.9.10\maven-repository\org\springframework\boot\spring-boot\3.1.5\spring-boot-3.1.5.jar;D:\apache-maven-3.9.10\maven-repository\jakarta\annotation\jakarta.annotation-api\2.1.1\jakarta.annotation-api-2.1.1.jar;D:\apache-maven-3.9.10\maven-repository\org\springframework\spring-core\6.0.13\spring-core-6.0.13.jar;D:\apache-maven-3.9.10\maven-repository\org\springframework\spring-jcl\6.0.13\spring-jcl-6.0.13.jar;D:\apache-maven-3.9.10\maven-repository\org\yaml\snakeyaml\1.33\snakeyaml-1.33.jar;D:\apache-maven-3.9.10\maven-repository\org\springframework\boot\spring-boot-starter-json\3.1.5\spring-boot-starter-json-3.1.5.jar;D:\apache-maven-3.9.10\maven-repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.15.3\jackson-datatype-jdk8-2.15.3.jar;D:\apache-maven-3.9.10\maven-repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.15.3\jackson-datatype-jsr310-2.15.3.jar;D:\apache-maven-3.9.10\maven-repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.15.3\jackson-module-parameter-names-2.15.3.jar;D:\apache-maven-3.9.10\maven-repository\org\springframework\boot\spring-boot-starter-tomcat\3.1.5\spring-boot-starter-tomcat-3.1.5.jar;D:\apache-maven-3.9.10\maven-repository\org\apache\tomcat\embed\tomcat-embed-core\10.1.15\tomcat-embed-core-10.1.15.jar;D:\apache-maven-3.9.10\maven-repository\org\apache\tomcat\embed\tomcat-embed-el\10.1.15\tomcat-embed-el-10.1.15.jar;D:\apache-maven-3.9.10\maven-repository\org\apache\tomcat\embed\tomcat-embed-websocket\10.1.15\tomcat-embed-websocket-10.1.15.jar;D:\apache-maven-3.9.10\maven-repository\org\springframework\spring-web\6.0.13\spring-web-6.0.13.jar;D:\apache-maven-3.9.10\maven-repository\org\springframework\spring-beans\6.0.13\spring-beans-6.0.13.jar;D:\apache-maven-3.9.10\maven-repository\io\micrometer\micrometer-observation\1.10.12\micrometer-observation-1.10.12.jar;D:\apache-maven-3.9.10\maven-repository\io\micrometer\micrometer-commons\1.10.12\micrometer-commons-1.10.12.jar;D:\apache-maven-3.9.10\maven-repository\org\springframework\spring-webmvc\6.0.13\spring-webmvc-6.0.13.jar;D:\apache-maven-3.9.10\maven-repository\org\springframework\spring-aop\6.0.13\spring-aop-6.0.13.jar;D:\apache-maven-3.9.10\maven-repository\org\springframework\spring-context\6.0.13\spring-context-6.0.13.jar;D:\apache-maven-3.9.10\maven-repository\org\springframework\spring-expression\6.0.13\spring-expression-6.0.13.jar;D:\apache-maven-3.9.10\maven-repository\com\alibaba\druid-spring-boot-starter\1.2.18\druid-spring-boot-starter-1.2.18.jar;D:\apache-maven-3.9.10\maven-repository\com\alibaba\druid\1.2.18\druid-1.2.18.jar;D:\apache-maven-3.9.10\maven-repository\org\springframework\boot\spring-boot-autoconfigure\1.5.22.RELEASE\spring-boot-autoconfigure-1.5.22.RELEASE.jar;D:\apache-maven-3.9.10\maven-repository\org\glassfish\jaxb\jaxb-runtime\2.3.2\jaxb-runtime-2.3.2.jar;D:\apache-maven-3.9.10\maven-repository\jakarta\xml\bind\jakarta.xml.bind-api\2.3.2\jakarta.xml.bind-api-2.3.2.jar;D:\apache-maven-3.9.10\maven-repository\org\glassfish\jaxb\txw2\2.3.2\txw2-2.3.2.jar;D:\apache-maven-3.9.10\maven-repository\com\sun\istack\istack-commons-runtime\3.0.8\istack-commons-runtime-3.0.8.jar;D:\apache-maven-3.9.10\maven-repository\org\jvnet\staxex\stax-ex\1.8.1\stax-ex-1.8.1.jar;D:\apache-maven-3.9.10\maven-repository\com\sun\xml\fastinfoset\FastInfoset\1.2.16\FastInfoset-1.2.16.jar;D:\apache-maven-3.9.10\maven-repository\jakarta\activation\jakarta.activation-api\1.2.1\jakarta.activation-api-1.2.1.jar;D:\apache-maven-3.9.10\maven-repository\org\mybatis\spring\boot\mybatis-spring-boot-starter\3.0.3\mybatis-spring-boot-starter-3.0.3.jar;D:\apache-maven-3.9.10\maven-repository\org\springframework\boot\spring-boot-starter-jdbc\3.2.0\spring-boot-starter-jdbc-3.2.0.jar;D:\apache-maven-3.9.10\maven-repository\com\zaxxer\HikariCP\5.0.1\HikariCP-5.0.1.jar;D:\apache-maven-3.9.10\maven-repository\org\springframework\spring-jdbc\6.1.1\spring-jdbc-6.1.1.jar;D:\apache-maven-3.9.10\maven-repository\org\springframework\spring-tx\6.1.1\spring-tx-6.1.1.jar;D:\apache-maven-3.9.10\maven-repository\org\mybatis\spring\boot\mybatis-spring-boot-autoconfigure\3.0.3\mybatis-spring-boot-autoconfigure-3.0.3.jar;D:\apache-maven-3.9.10\maven-repository\org\mybatis\mybatis\3.5.14\mybatis-3.5.14.jar;D:\apache-maven-3.9.10\maven-repository\org\mybatis\mybatis-spring\3.0.3\mybatis-spring-3.0.3.jar;D:\apache-maven-3.9.10\maven-repository\org\projectlombok\lombok\1.18.30\lombok-1.18.30.jar;D:\apache-maven-3.9.10\maven-repository\jakarta\enterprise\jakarta.enterprise.cdi-api\3.0.0\jakarta.enterprise.cdi-api-3.0.0.jar;D:\apache-maven-3.9.10\maven-repository\jakarta\el\jakarta.el-api\4.0.0\jakarta.el-api-4.0.0.jar;D:\apache-maven-3.9.10\maven-repository\jakarta\interceptor\jakarta.interceptor-api\2.0.0\jakarta.interceptor-api-2.0.0.jar;D:\apache-maven-3.9.10\maven-repository\jakarta\inject\jakarta.inject-api\2.0.0\jakarta.inject-api-2.0.0.jar;D:\apache-maven-3.9.10\maven-repository\jakarta\ws\rs\jakarta.ws.rs-api\3.0.0\jakarta.ws.rs-api-3.0.0.jar;D:\apache-maven-3.9.10\maven-repository\jakarta\servlet\jakarta.servlet-api\5.0.0\jakarta.servlet-api-5.0.0.jar;D:\apache-maven-3.9.10\maven-repository\com\fasterxml\jackson\core\jackson-databind\2.15.3\jackson-databind-2.15.3.jar;D:\apache-maven-3.9.10\maven-repository\com\fasterxml\jackson\core\jackson-annotations\2.15.3\jackson-annotations-2.15.3.jar;D:\apache-maven-3.9.10\maven-repository\com\fasterxml\jackson\core\jackson-core\2.15.3\jackson-core-2.15.3.jar;D:\apache-maven-3.9.10\maven-repository\org\slf4j\slf4j-api\2.0.12\slf4j-api-2.0.12.jar;D:\apache-maven-3.9.10\maven-repository\org\apache\logging\log4j\log4j-slf4j2-impl\2.23.1\log4j-slf4j2-impl-2.23.1.jar;D:\apache-maven-3.9.10\maven-repository\org\apache\logging\log4j\log4j-api\2.23.1\log4j-api-2.23.1.jar;D:\apache-maven-3.9.10\maven-repository\org\apache\logging\log4j\log4j-core\2.23.1\log4j-core-2.23.1.jar com.example.fundprofit.FundProfitApplication . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v3.1.5) 2025-07-12T10:34:20.673+08:00 INFO 5860 --- [ main] c.e.f.FundProfitApplication : Starting FundProfitApplication using Java 17.0.15 with PID 5860 (C:\Users\Administrator\Desktop\考题示例\考题示例\demo\target\classes started by Administrator in C:\Users\Administrator\Desktop\考题示例\考题示例\demo) 2025-07-12T10:34:20.680+08:00 INFO 5860 --- [ main] c.e.f.FundProfitApplication : No active profile set, falling back to 1 default profile: "default" 2025-07-12T10:34:20.845+08:00 WARN 5860 --- [ main] o.s.b.d.FailureAnalyzers : FailureAnalyzers [org.springframework.boot.autoconfigure.diagnostics.analyzer.NoSuchBeanDefinitionFailureAnalyzer] implement BeanFactoryAware or EnvironmentAware. Support for these interfaces on FailureAnalyzers is deprecated, and will be removed in a future release. Instead provide a constructor that accepts BeanFactory or Environment parameters. 2025-07-12T10:34:20.847+08:00 ERROR 5860 --- [ main] o.s.b.SpringApplication : Application run failed java.lang.NoClassDefFoundError: org/springframework/boot/bind/RelaxedPropertyResolver at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getExcludeAutoConfigurationsProperty(AutoConfigurationImportSelector.java:205) ~[spring-boot-autoconfigure-1.5.22.RELEASE.jar:1.5.22.RELEASE] at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getExclusions(AutoConfigurationImportSelector.java:199) ~[spring-boot-autoconfigure-1.5.22.RELEASE.jar:1.5.22.RELEASE] at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.selectImports(AutoConfigurationImportSelector.java:96) ~[spring-boot-autoconfigure-1.5.22.RELEASE.jar:1.5.22.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser$DefaultDeferredImportSelectorGroup.process(ConfigurationClassParser.java:821) ~[spring-context-6.0.13.jar:6.0.13] at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGrouping.getImports(ConfigurationClassParser.java:796) ~[spring-context-6.0.13.jar:6.0.13] at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:726) ~[spring-context-6.0.13.jar:6.0.13] at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process(ConfigurationClassParser.java:697) ~[spring-context-6.0.13.jar:6.0.13] at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:182) ~[spring-context-6.0.13.jar:6.0.13] at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:415) ~[spring-context-6.0.13.jar:6.0.13] at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:287) ~[spring-context-6.0.13.jar:6.0.13] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:344) ~[spring-context-6.0.13.jar:6.0.13] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:115) ~[spring-context-6.0.13.jar:6.0.13] at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:779) ~[spring-context-6.0.13.jar:6.0.13] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:597) ~[spring-context-6.0.13.jar:6.0.13] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.1.5.jar:3.1.5] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:738) [spring-boot-3.1.5.jar:3.1.5] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:440) [spring-boot-3.1.5.jar:3.1.5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-3.1.5.jar:3.1.5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) [spring-boot-3.1.5.jar:3.1.5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) [spring-boot-3.1.5.jar:3.1.5] at com.example.fundprofit.FundProfitApplication.main(FundProfitApplication.java:11) [classes/:?] Caused by: java.lang.ClassNotFoundException: org.springframework.boot.bind.RelaxedPropertyResolver at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[?:?] at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[?:?] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525) ~[?:?] ... 21 more 进程已结束,退出代码为 1 请解释下原因给出方法

filetype

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2025-03-16 23:43:33.925 ERROR 19808 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: An attempt was made to call a method that does not exist. The attempt was made from the following location: org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:177) The following method did not exist: 'javax.servlet.ServletContext org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContext()' The calling method's class, org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext, was loaded from the following location: jar:file:/C:/Users/%e5%b0%8f%e7%99%bd/.m2/repository/org/springframework/boot/spring-boot/2.6.13/spring-boot-2.6.13.jar!/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContext.class The called method's class, org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext, is available from the following locations: jar:file:/C:/Users/%e5%b0%8f%e7%99%bd/.m2/repository/org/springframework/boot/spring-boot/2.6.13/spring-boot-2.6.13.jar!/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContext.class The called method's class hierarchy was loaded from the following locations: org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext: file:/C:/Users/%e5%b0%8f%e7%99%bd/.m2/repository/org/springframework/boot/spring-boot/2.6.13/spring-boot-2.6.13.jar org.springframework.web.context.support.GenericWebApplicationContext: file:/C:/Users/%e5%b0%8f%e7%99%bd/.m2/repository/org/springframework/spring-web/6.0.11/spring-web-6.0.11.jar org.springframework.context.support.GenericApplicationContext: file:/C:/Users/%e5%b0%8f%e7%99%bd/.m2/repository/org/springframework/spring-context/5.3.23/spring-context-5.3.23.jar org.springframework.context.support.AbstractApplicationContext: file:/C:/Users/%e5%b0%8f%e7%99%bd/.m2/repository/org/springframework/spring-context/5.3.23/spring-context-5.3.23.jar org.springframework.core.io.DefaultResourceLoader: file:/C:/Users/%e5%b0%8f%e7%99%bd/.m2/repository/org/springframework/spring-core/5.3.23/spring-core-5.3.23.jar Action: Correct the classpath of your application so that it contains a single, compatible version of org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext Process finished with exit code 1

dilikong
  • 粉丝: 35
上传资源 快速赚钱