forked from spring-projects/spring-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Two choices are available to users for welcome page
* For a jar deployment add classpath:static/index.html (works via Spring MVC mapping) * For a war the same thing works, but so does adding index.html to src/main/webapp (works via container default servlet) [Fixes #54092261] [bs-252]
- Loading branch information
Showing
13 changed files
with
247 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?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> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-samples</artifactId> | ||
<version>0.5.0.BUILD-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>spring-boot-sample-web-static</artifactId> | ||
<packaging>war</packaging> | ||
<properties> | ||
<main.basedir>${basedir}/../..</main.basedir> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>spring-boot-up-web</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>spring-boot-up-tomcat</artifactId> | ||
<version>${project.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
33 changes: 33 additions & 0 deletions
33
...b-static/src/main/java/org/springframework/boot/sample/ui/SampleWebStaticApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2013 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.sample.ui; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@EnableAutoConfiguration | ||
@ComponentScan | ||
public class SampleWebStaticApplication { | ||
|
||
public static void main(String[] args) throws Exception { | ||
SpringApplication.run(SampleWebStaticApplication.class, args); | ||
} | ||
|
||
} |
Empty file.
Binary file added
BIN
+2.79 KB
spring-boot-samples/spring-boot-sample-web-static/src/main/resources/favicon.ico
Binary file not shown.
7 changes: 7 additions & 0 deletions
7
spring-boot-samples/spring-boot-sample-web-static/src/main/resources/logback.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
|
||
<include resource="org/springframework/boot/logging/logback/base.xml"/> | ||
<logger name="org.springframework" level="DEBUG"/> | ||
|
||
</configuration> |
11 changes: 11 additions & 0 deletions
11
spring-boot-samples/spring-boot-sample-web-static/src/main/webapp/css/bootstrap.min.css
Large diffs are not rendered by default.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
spring-boot-samples/spring-boot-sample-web-static/src/main/webapp/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Static</title> | ||
<link rel="stylesheet" href="/css/bootstrap.min.css"/> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<div class="navbar"> | ||
<div class="navbar-inner"> | ||
<a class="brand" | ||
href="https://github.com/SpringSource/spring-boot"> | ||
Spring Boot | ||
</a> | ||
<ul class="nav"> | ||
<li> | ||
<a href="/"> | ||
Home | ||
</a> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
<h1>Home</h1> | ||
<div> | ||
Some static content | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
84 changes: 84 additions & 0 deletions
84
...tic/src/test/java/org/springframework/boot/sample/ui/SampleWebStaticApplicationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package org.springframework.boot.sample.ui; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.http.client.ClientHttpResponse; | ||
import org.springframework.web.client.DefaultResponseErrorHandler; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* Basic integration tests for demo application. | ||
* | ||
* @author Dave Syer | ||
*/ | ||
public class SampleWebStaticApplicationTests { | ||
|
||
private static ConfigurableApplicationContext context; | ||
|
||
@BeforeClass | ||
public static void start() throws Exception { | ||
Future<ConfigurableApplicationContext> future = Executors | ||
.newSingleThreadExecutor().submit( | ||
new Callable<ConfigurableApplicationContext>() { | ||
@Override | ||
public ConfigurableApplicationContext call() throws Exception { | ||
return (ConfigurableApplicationContext) SpringApplication | ||
.run(SampleWebStaticApplication.class); | ||
} | ||
}); | ||
context = future.get(30, TimeUnit.SECONDS); | ||
} | ||
|
||
@AfterClass | ||
public static void stop() { | ||
if (context != null) { | ||
context.close(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testHome() throws Exception { | ||
ResponseEntity<String> entity = getRestTemplate().getForEntity( | ||
"http://localhost:8080", String.class); | ||
assertEquals(HttpStatus.OK, entity.getStatusCode()); | ||
assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(), entity | ||
.getBody().contains("<title>Static")); | ||
} | ||
|
||
@Test | ||
public void testCss() throws Exception { | ||
ResponseEntity<String> entity = getRestTemplate().getForEntity( | ||
"http://localhost:8080/resources/css/bootstrap.min.css", String.class); | ||
assertEquals(HttpStatus.OK, entity.getStatusCode()); | ||
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body")); | ||
assertEquals("Wrong content type:\n" + entity.getHeaders().getContentType(), | ||
MediaType.valueOf("text/css"), entity.getHeaders().getContentType()); | ||
} | ||
|
||
private RestTemplate getRestTemplate() { | ||
RestTemplate restTemplate = new RestTemplate(); | ||
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() { | ||
@Override | ||
public void handleError(ClientHttpResponse response) throws IOException { | ||
} | ||
}); | ||
return restTemplate; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters