我正在學習Spring引導,雖然我可以運行我的項目,但當我嘗試訪問它時,希望獲得一個空白頁面,我得到一個登錄名/密碼提示,儘管我已在我的應用程序中定義了一些值。屬性文件,我總是得到一個錯誤。如何登錄到我的新彈簧啓動應用程序?
pom.xml
是:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>b.c.g</groupId>
<artifactId>app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>appName</name>
<description>appDescription</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<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-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mobile</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-social-facebook</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-social-twitter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties
是:
spring.datasource.url = jdbc:mysql://localhost:3306/app
spring.datasource.name=app
spring.datasource.username=app
spring.datasource.password=appPassword
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.database=mysql
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
security.user.name=master
security.user.password=abc123
最後,我的主類是:
@Configuration
@EnableAutoConfiguration
@ComponentScan
@Controller
public class AppNameApplication {
@ResponseBody
@RequestMapping(value = "/")
public String entry() {
return "AppName";
}
public static void main(String[] args) {
SpringApplication.run(AppNameApplication.class, args);
}
}
雖然我是一個有經驗的Spring用戶,我學習Spring引導以增加我的開發技能。
我得到在瀏覽器上的錯誤是:
白色標籤錯誤頁面
該應用對/錯誤沒有明確的映射,所以你看到 此作爲後備。 Tue Aug 09 13:33:59 BRT 2016有一個 意外錯誤(type = Unauthorized,status = 401)。 Bad credentials
我知道現在沒有什麼事情了,但這是預期的行爲嗎?我不應該,至少能夠登錄嗎?
你是什麼意思登錄?你的應用的哪個部分管理用戶和/或認證他們? –
您正在使用spring安全啓動程序,因此我認爲您可以先嚐試刪除它,以檢查是否可以訪問您的端點。如果可行,那麼你需要學習如何配置彈簧安全。順便說一句,如果你想學習SpringBoot一步一步開始,而不是在一次拍攝中添加所有內容。 –
請參閱此處瞭解Spring引導安全配置:http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-security – woemler