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

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

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

Spring Framework は、Javaプラットフォーム向けのオープンソースアプリケーションフレームワークです。 Java Platform上に、 Web ベースのアプリケーションを設計するための拡張機能が数多く用意されています。

Apache Maven 2

Apache Mavenは、ソフトウェアプロジェクトの管理ツールです。

Q&A

解決済

1回答

6058閲覧

【Spring】pom.xmlにprofileを定義し読み込みファイルの切り替えができない。

montai21

総合スコア15

Spring

Spring Framework は、Javaプラットフォーム向けのオープンソースアプリケーションフレームワークです。 Java Platform上に、 Web ベースのアプリケーションを設計するための拡張機能が数多く用意されています。

Apache Maven 2

Apache Mavenは、ソフトウェアプロジェクトの管理ツールです。

0グッド

0クリップ

投稿2020/03/22 02:40

編集2020/03/22 06:40

#事象
pom.xmlにデータベース接続時の値を記述してあるpropertiesファイルの読み込みを環境に合わして切り替えるように定義し、サーバを起動したら、404エラーがでてwebページにアクセスできませんでした。
解決方法を教えていただけないでしょうか?

#コンソールログ

10:56:40.053 [main] INFO org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started 10:56:40.194 [main] DEBUG org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext 10:56:40.372 [main] DEBUG org.springframework.ui.context.support.UiApplicationContextUtils - Unable to locate ThemeSource with name 'themeSource': using default [org.springframework.ui.context.support.ResourceBundleThemeSource@5c04ec8] 10:56:40.381 [main] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/spring.liveBeansView.mbeanDomain] 10:56:40.385 [main] DEBUG org.springframework.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/spring.liveBeansView.mbeanDomain] not found - trying original name [spring.liveBeansView.mbeanDomain]. javax.naming.NameNotFoundException: 名前 [spring.liveBeansView.mbeanDomain] はこのコンテキストにバインドされていません 10:56:40.385 [main] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [spring.liveBeansView.mbeanDomain] 10:56:40.386 [main] DEBUG org.springframework.jndi.JndiPropertySource - JNDI lookup for name [spring.liveBeansView.mbeanDomain] threw NamingException with message: 名前 [spring.liveBeansView.mbeanDomain] はこのコンテキストにバインドされていません. Returning null. 10:56:40.412 [main] INFO org.springframework.web.context.ContextLoader - Root WebApplicationContext initialized in 350 ms 10:56:41.082 [main] DEBUG org.terasoluna.gfw.web.logging.mdc.MDCClearFilter - Filter 'MDCClearFilter' configured for use 10:56:41.082 [main] DEBUG org.terasoluna.gfw.web.logging.mdc.XTrackMDCPutFilter - Filter 'XTrackMDCPutFilter' configured for use 10:56:41.224 [main] DEBUG org.springframework.web.filter.CharacterEncodingFilter - Filter 'CharacterEncodingFilter' configured for use

#pom.xml

pom.xml

1<?xml version="1.0" encoding="UTF-8"?> 2<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"> 3 <modelVersion>4.0.0</modelVersion> 4 <groupId>com.example.taskmanagement</groupId> 5 <artifactId>taskmanagement</artifactId> 6 <version>1.0.0-SNAPSHOT</version> 7 <packaging>war</packaging> 8 <parent> 9 <groupId>org.terasoluna.gfw</groupId> 10 <artifactId>terasoluna-gfw-parent</artifactId> 11 <version>5.5.1.RELEASE</version> 12 </parent> 13 14 <name>TERASOLUNA Server Framework for Java (5.x) Web Blank Project (MyBatis3)</name> 15 <description>Web Blank Project (MyBatis3) using TERASOLUNA Server Framework for Java (5.x)</description> 16 <url>http://terasoluna.org</url> 17 <inceptionYear>2013</inceptionYear> 18 <licenses> 19 <license> 20 <name>Apache License, Version 2.0</name> 21 <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> 22 <distribution>manual</distribution> 23 </license> 24 </licenses> 25 <organization> 26 <name>TERASOLUNA Framework Team</name> 27 <url>http://terasoluna.org</url> 28 </organization> 29 30 <profiles> 31 <profile> 32 <id>xtest</id> 33 <properties> 34 <maven.test.skip>true</maven.test.skip> 35 </properties> 36 </profile> 37 <profile> 38 <id>local</id> 39 <activation> 40 <activeByDefault>true</activeByDefault> 41 </activation> 42 <properties> 43 <env>local</env> 44 </properties> 45 </profile> 46 <profile> 47 <id>heroku</id> 48 <properties> 49 <env>heroku</env> 50 </properties> 51 </profile> 52 </profiles> 53 <build> 54 <filters> 55 <filter>src/main/resources/META-INF/spring/taskmanagement-infra.${env}.properties</filter> 56 </filters> 57 <resources> 58 <resource> 59 <directory>src/main/resources/META-INF/spring</directory> 60 <filtering>true</filtering> 61 <includes> 62 <include>taskmanagement-infra.${env}.properties</include> 63 </includes> 64 </resource> 65 </resources> 66 <pluginManagement> 67 <plugins> 68 <plugin> 69 <groupId>org.codehaus.mojo</groupId> 70 <artifactId>build-helper-maven-plugin</artifactId> 71 <version>${org.codehaus.mojo.build-helper-maven-plugin.version}</version> 72 <executions> 73 <execution> 74 <id>add-source</id> 75 <phase>generate-sources</phase> 76 <goals> 77 <goal>add-source</goal> 78 </goals> 79 <configuration> 80 <sources> 81 <source>src/generated/java</source> 82 </sources> 83 </configuration> 84 </execution> 85 <execution> 86 <id>add-resource</id> 87 <phase>generate-resources</phase> 88 <goals> 89 <goal>add-resource</goal> 90 </goals> 91 <configuration> 92 <resources> 93 <resource> 94 <directory>src/generated/resources</directory> 95 </resource> 96 </resources> 97 </configuration> 98 </execution> 99 </executions> 100 </plugin> 101 <plugin> 102 <groupId>org.apache.maven.plugins</groupId> 103 <artifactId>maven-war-plugin</artifactId> 104 <version>${maven-war-plugin.version}</version> 105 <configuration> 106 <warName>${project.artifactId}</warName> 107 <archive> 108 <addMavenDescriptor>false</addMavenDescriptor> 109 <manifest> 110 <addDefaultImplementationEntries>true</addDefaultImplementationEntries> 111 </manifest> 112 </archive> 113 </configuration> 114 </plugin> 115 </plugins> 116 </pluginManagement> 117 </build>

#src配下のツリー構造(一部)

src ├─main ├─resources └─META-INF ├─dozer │ .gitkeep │ ├─mybatis │ mybatis-config.xml │ └─spring applicationContext.xml spring-mvc.xml spring-security.xml taskmanagement-codelist.xml taskmanagement-domain.xml taskmanagement-env.xml taskmanagement-infra.heroku.properties taskmanagement-infra.local.properties taskmanagement-infra.xml

##試したこと
以下のサイトを参考にweb.xmlにcontext-parmaを追加したのですが、だめでした。
https://stackoverrun.com/ja/q/6507414

また、プロファイルでpropertiesファイルを切り替える処理を追加していない状態に戻し、起動したところ問題なく動作してるのは確認したため、pomの記述方法が間違っていると思うのですが、いろいろサイトをみましたが、解決方法がわかりませんでした。

##補足
フレームワークはTERASOLUNAを使っているのですが、それが何かの原因の要素にもなっているのでしょうか?

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

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

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

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

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

guest

回答1

0

自己解決

mavenはビルド時に<resources>タグの<directory>タグで定義しているパスの配下をコピーする仕様でかつ、<include>タグで指定したファイルのみコピーする仕様であったためpropertiesファイル以外のxmlファイルなどのコピーができていなかったのが原因であったとわかりました。(mavenの仕様についての自分の理解が上記の内容であっているかは少し不安ですが)
なので、<directory>のパスをsrc/main/resourcesにし<include>タグを排除すると問題なく起動できました。
あまり理解せずに使っていたことがあだになりました(笑)

投稿2020/03/22 06:37

montai21

総合スコア15

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問