2016-11-05 9 views
0

挨拶:は、http Webページを参照してくださいしないでください:// localhostを:8080 /私は構造を持つプロジェクト持って

enter image description here

build.gradle

buildscript { 
    ext { 
     springBootVersion = '1.4.1.RELEASE' 
    } 
    repositories { 
     mavenCentral() 
     mavenLocal() 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
    } 
} 

apply plugin: 'war' 
apply plugin: 'spring-boot' 

jar { 
    baseName = 'accouting' 
    version = '0.0.1-SNAPSHOT' 
} 

sourceCompatibility = 1.8 
targetCompatibility = 1.8 

repositories { 
    mavenCentral() 
    mavenLocal() 
} 

dependencies { 
    compile('org.springframework.boot:spring-boot-starter-data-jpa') 
    compile('org.springframework.boot:spring-boot-starter-web') 
    compile("org.springframework.boot:spring-boot-starter-thymeleaf") 
    compile("org.springframework.boot:spring-boot-devtools") 
    compile('com.oracle:ojdbc6:11.2.0.4') 
    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat') 
    testCompile('org.springframework.boot:spring-boot-starter-test') 
} 

Application.java

package com.example; 

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.boot.builder.SpringApplicationBuilder; 
import org.springframework.boot.web.support.SpringBootServletInitializer; 

@SpringBootApplication 
public class Application extends SpringBootServletInitializer { 

    @Override 
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 
     return application.sources(Application.class); 
    } 

    public static void main(String[] args) throws Exception { 
     SpringApplication.run(Application.class, args); 
    } 

} 

GreetingController.java

package hello; 

import org.springframework.stereotype.Controller; 
import org.springframework.ui.Model; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestParam; 

@Controller 
public class GreetingController { 

    @RequestMapping("/greeting") 
    public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) { 
     model.addAttribute("name", name); 
     return "greeting"; 
    } 

} 

index.html

<!DOCTYPE HTML> 
<html> 
<head> 
    <title>Getting Started: Serving Web Content</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
</head> 
<body> 
<p>Get your greeting <a href="/greeting">here</a></p> 
</body> 
</html> 

application.properties

#Basic Spring Boot Config for Oracle 
spring.datasource.url=jdbc:oracle:thin:@//192.168.1.42:1521/xe 
spring.datasource.username=system 
spring.datasource.password=123456 
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver 
datasource.mine.poolSize=30 

# Hibernate config 
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect 
spring.mvc.view.prefix=/ 
spring.mvc.view.suffix=.jsp 

greeting.html

<!DOCTYPE HTML> 
<html xmlns:th="http://www.thymeleaf.org"> 
<head> 
    <title>Getting Started: Serving Web Content</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
</head> 
<body> 
<p th:text="'Hello, ' + ${name} + '!'" /> 
</body> 
</html> 

私はそれを修正する方法を、http://localhost:8080/greetingでWebページが表示されませんか?

+0

オフトピック。しかし、私はこれが何であるかを知ることができます.... < – Jay

+0

@Jay Spring Tool Suiteは、Springアプリケーション開発者向けにカスタマイズされたEclipseのバージョンです。 –

+0

@ DoNhuVyあなたはwarファイルを作成しているようです。あなたはTomcatにそれを配備していますか?ログはアプリケーションが正常に起動したことを示しますか?できるだけスニペットを共有してください。 –

答えて

2

GreetingControllerは別のパッケージに含まれています。 com.exampleに移動すると、問題が解決するはずです。

それでも、パッケージ構造を保つ@ComponentScan(basePackages = "hello")を使用して、我々が持っているしたい場合:

package com.example; 

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.boot.builder.SpringApplicationBuilder; 
import org.springframework.boot.web.support.SpringBootServletInitializer; 
import org.springframework.context.annotation.ComponentScan; 

@SpringBootApplication 
@ComponentScan(basePackages = "hello") 
public class Application extends SpringBootServletInitializer { 

    @Override 
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 
     return application.sources(Application.class); 
    } 

    public static void main(String[] args) throws Exception { 
     SpringApplication.run(Application.class, args); 
    } 

} 
関連する問題