質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

IntelliJ IDEA

IntelliJ IDEA(インテリジェイ アイディア)は、JetBrains社が開発した、 JavaやScalaなどで利用される統合開発環境です。

Thymeleaf

Thymeleaf(タイムリーフ)とは、Java用のテンプレートエンジンで、特定のフレームワークに依存せず使用することが可能です。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

Q&A

1回答

3511閲覧

springbootでthymeleafをtemplatesとして利用できません

shuhey

総合スコア18

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

IntelliJ IDEA

IntelliJ IDEA(インテリジェイ アイディア)は、JetBrains社が開発した、 JavaやScalaなどで利用される統合開発環境です。

Thymeleaf

Thymeleaf(タイムリーフ)とは、Java用のテンプレートエンジンで、特定のフレームワークに依存せず使用することが可能です。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

0グッド

0クリップ

投稿2016/08/01 02:00

編集2016/08/01 04:07

表題の通りです。
IDEはIntelliJでpom.xmlのファイルも編集しreimportsも行ったものの、サーバーも起動しません。

templatesを使用し始めてからうまく動作しなくなりました。
エラーメッセージには、mainClassがないと書いてありますが、今までmainと書かなくても動作していたのですが、、、

参照している教材は『Spring Boot プログラミング入門』という本です。
解決策をご存知の方、教えていただけないでしょうか。

html

1index.html 2 3<!DOCTYPE html> 4<html xmlns:th="http://www.thymeleaf.org"> 5<head> 6 <title>top page</title> 7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 8 <style> 9 h1 { font-size: 18pt; font-weight: bold; color: gray; } 10 body { font-size:13pt; color: gray; margin:5px 25px;} 11 </style> 12</head> 13<body> 14 <h1>Hello Page</h1> 15 <p class="msg">this is Thymeleaf sample page.</p> 16</body> 17</html>

java

1HelloController.java 2 3package pro.shu; 4 5import org.springframework.stereotype.Controller; 6import org.springframework.web.bind.annotation.RequestMapping; 7 8@Controller 9public class HelloController { 10 @RequestMapping("/") 11 public String index() { 12 return "index"; 13 } 14 15}

xml

1pom.xml 2 3<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <modelVersion>4.0.0</modelVersion> 6 7 <groupId>pro.shu</groupId> 8 <artifactId>my-spring-boot</artifactId> 9 <version>1.0-SNAPSHOT</version> 10 <packaging>jar</packaging> 11 12 <name>my-spring-boot</name> 13 <url>http://maven.apache.org</url> 14 15 <properties> 16 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 17 </properties> 18 19 <parent> 20 <groupId>org.springframework.boot</groupId> 21 <artifactId>spring-boot-starter-parent</artifactId> 22 <version>1.4.0.RELEASE</version> 23 </parent> 24 25 <dependencies> 26 <dependency> 27 <groupId>org.springframework.boot</groupId> 28 <artifactId>spring-boot-starter-web</artifactId> 29 </dependency> 30 <dependency> 31 <groupId>org.springframework.boot</groupId> 32 <artifactId>spring-boot-starter-thymeleaf</artifactId> 33 </dependency> 34 <dependency> 35 <groupId>junit</groupId> 36 <artifactId>junit</artifactId> 37 <version>4.12</version> 38 <scope>test</scope> 39 </dependency> 40 <dependency> 41 <groupId>org.thymeleaf</groupId> 42 <artifactId>thymeleaf-spring4</artifactId> 43 </dependency> 44 </dependencies> 45 46 <build> 47 <plugins> 48 <plugin> 49 <groupId>org.springframework.boot</groupId> 50 <artifactId>spring-boot-maven-plugin</artifactId> 51 <version>1.4.0.RELEASE</version> 52 <executions> 53 <execution> 54 <goals> 55 <goal>repackage</goal> 56 </goals> 57 </execution> 58 </executions> 59 </plugin> 60 </plugins> 61 </build> 62 63</project>
エラーメッセージ [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.0.RELEASE:run (default-cli) on project my-spring-boot: Unable to find a suitable main class, please add a 'mainClass' property -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

java

1package sample.spring; 2 3import org.springframework.context.annotation.Bean; 4import org.springframework.context.annotation.ComponentScan; 5import org.springframework.context.annotation.Configuration; 6import org.springframework.context.annotation.PropertySource; 7import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; 8 9@Configuration 10@ComponentScan 11@PropertySource(value = {"classpath:beans.properties"}) 12public class AppConfig { 13 14 @Bean 15 public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { 16 return new PropertySourcesPlaceholderConfigurer(); 17 } 18 19}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

A-pZ

2016/08/01 02:14

SpringとThymeleafを連係する設定ないしはJavaConfigも記載されると解答が得られるかもしれません。
shuhey

2016/08/01 04:02

連携の設定は、pom.xmlのdependencyに記載の箇所と思っていたのですが、違うのでしょうか...?また、JavaConfigはネットで探してきたものを追記したのですが、これを自分で生成する必要があるということでしょうか?
guest

回答1

0

Spring Bootはmain関数を持ったクラスを実行する事で内臓のTomcatなどが起動するはずですが。。。
main関数持ったクラスは本当にないですか?
ないなら以下のようにして試してみてください。

main関数を持ったクラスを追加

package pro.shu; @SpringBootApplication public class App { public static void main(String[] args) { SpringApplication.run(App.class, args); } }

pom.xml

<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>1.4.0.RELEASE</version> <configuration> <mainClass>pro.shu.App</mainClass> <layout>ZIP</layout> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>

投稿2016/08/03 07:29

guzzle

総合スコア43

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問