[麦芽项目 day one] 一、初步搭建SpringBoot+Druid环境
准备搞一套springcloud的电商全套,在这里记录下,每次所做的,这样可以有所沉淀。
首先搭建整体项目,技术采用:springcloud全家桶+mybatis+druid+rabbitmq+xxljob+elasticsearch
模块包括:用户模块、购物车模块、商品模块、订单模块、基础服务模块、接口模块、后台管理模块.....等
先解决掉用户模块。
pom引用:
1 <?xml version="1.0" encoding="UTF-8"?> 23 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 4.0.0 5 6com.maiya 7shopcloud-account 80.0.1-SNAPSHOT 9jar 10 11shopcloud-account 12shopcloud-account inilization 13 1415 19 20shopcloud-provider 16com.maiya.shopcloud 171.0-SNAPSHOT 1821 25 26UTF-8 22UTF-8 231.8 2427 28 7229 32io.springfox 30springfox-swagger-ui 3133 36io.springfox 34springfox-swagger2 3537 40com.alibaba 38druid-spring-boot-starter 3941 44mysql 42mysql-connector-java 4345 48 49org.springframework.boot 46spring-boot-starter-jdbc 4750 54com.maiya 51shopcloud-account-api 52${version} 5355 59junit 56junit 57test 5860 64org.springframework.boot 61spring-boot-test 62test 6365 70 71org.springframework 66spring-test 67RELEASE 68test 6973 81 82 8374 8075 78 79org.springframework.boot 76spring-boot-maven-plugin 77
application-dev.yml配置如下(主要是druid数据源的配置):
server: port: 8081 eureka: client: fetch-registry: false register-with-eureka: false spring: datasource: druid: max-active: 20 min-idle: 5 initial-size: 1 max-wait: 60000 test-on-borrow: true test-on-return: false test-while-idle: true validation-query: select 1 from dual pool-prepared-statements: false stat-view-servlet: url-pattern: /druid/* reset-enable: true login-username: admin login-password: admin enabled: true web-stat-filter: enabled: true url: jdbc:mysql://118.89.173.110:3306/sinoeshop?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false username: root password: MyNewPass4!
刚开始启动报错:
java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType
1 2018-09-13 22:21:51.347 ERROR 12785 --- [ main] o.s.boot.SpringApplication : Application startup failed 2 3 org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSource': Unsatisfied dependency expressed through field 'basicProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.jdbc.DataSourceProperties]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseType 4 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 5 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 6 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 7 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1272) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 8 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 9 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 10 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 11 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 12 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 13 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 14 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 15 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE] 16 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE] 17 at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE] 18 at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE] 19 at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE] 20 at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE] 21 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE] 22 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE] 23 at com.maiya.shopcloud.account.ShopcloudAccountApplication.main(ShopcloudAccountApplication.java:11) [classes/:na] 24 Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.jdbc.DataSourceProperties]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseType 25 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1163) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 26 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1107) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 27 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 28 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 29 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 30 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 31 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 32 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 33 at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 34 at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 35 at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 36 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 37 ... 19 common frames omitted 38 Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.jdbc.DataSourceProperties]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseType 39 at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:154) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 40 at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 41 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1155) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 42 ... 30 common frames omitted 43 Caused by: java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseType 44 at org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection.(EmbeddedDatabaseConnection.java:50) ~[spring-boot-autoconfigure-1.5.13.RELEASE.jar:1.5.13.RELEASE] 45 at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties. (DataSourceProperties.java:155) ~[spring-boot-autoconfigure-1.5.13.RELEASE.jar:1.5.13.RELEASE] 46 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_181] 47 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_181] 48 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_181] 49 at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_181] 50 at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE] 51 ... 32 common frames omitted 52 Caused by: java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType 53 at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_181] 54 at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_181] 55 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[na:1.8.0_181] 56 at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_181] 57 ... 39 common frames omitted
经排查是pom少引用了个包:
org.springframework.boot
spring-boot-starter-jdbc
成功后: