Spring Cloud踩坑記錄

報錯 Whitelabel Error Page

緣由是把Application.java放在了以下所示:java

Whitelabel Error Page

解決: 把Application.java放到最外層便可解決web

輸入圖片說明

啓動報錯ClassNotFoundException: feign.Feign$Builder

緣由: 包的問題。 解決方案, 修改pom文件spring

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-feign</artifactId>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.SR4</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

搭建Spring Cloud Bus Demo時,啓動報錯。

Caused by: java.lang.NoClassDefFoundError: org/springframework/security/config/http/SessionCreationPolicy
	at org.springframework.boot.actuate.autoconfigure.ManagementServerProperties$Security.<init>(ManagementServerProperties.java:186) ~[spring-boot-actuator-1.4.0.RELEASE.jar:1.4.0.RELEASE]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_162]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_162]
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_162]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_162]
	at java.lang.Class.newInstance(Class.java:442) ~[na:1.8.0_162]
	at org.springframework.beans.BeanUtils.instantiate(BeanUtils.java:77) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.beans.AbstractNestablePropertyAccessor.newValue(AbstractNestablePropertyAccessor.java:914) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	... 125 common frames omitted

報錯信息如圖所示: 輸入圖片說明 出錯緣由: 由於沒有找到該類。因此就出現這個問題,由於咱們在配置消息總線時加入了該配置:management.security.enable=false,該配置須要對Spring的security包產生依賴。但在項目pom中並無去依賴Spring的security包。安全

解決方案: 在pom文件中增長對security包的依賴:app

<!-- 對Spring security安全包的依賴,不然會報錯 -->
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-security</artifactId>
</dependency>

報錯:

DiscoveryClient_SPRINGCLOUD-QUERYDSL/10.0.2.140:springcloud-querydsl:4445 - was unable to refresh its cache! status = Cannot execute request on any known server

緣由: 沒有啓動註冊中心,致使服務沒法進行註冊,因此會報Cannot execute request on any known server 解決方案: 啓動註冊中心maven

報錯:

org.hibernate.MappingException: Could not determine type for: java.util.List, at table: teacher, for columns: [org.hibernate.mapping.Column(students)]

緣由: 由於Teacher與Student是一對多關係,在Teacher裏面有List<Student>這麼一個引用,因此須要指定它們之間的關係、好比@OneToMany、@ManyToOne等。 解決方案: 指定相應的關係便可。spring-boot

相關文章
相關標籤/搜索