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

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

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

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

Java

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

Spring

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

Eclipse

Eclipseは、IBM社で開発された統合開発環境のひとつです。2001年11月にオープンソース化されました。 たくさんのプラグインがあり自由に機能を追加をすることができるため、開発ツールにおける共通プラットフォームとして位置づけられています。 Eclipse自体は、Javaで実装されています。

Q&A

解決済

1回答

10180閲覧

springのapplication-config.xmlでエラーが出ます。

y-baminami

総合スコア11

MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

Java

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

Spring

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

Eclipse

Eclipseは、IBM社で開発された統合開発環境のひとつです。2001年11月にオープンソース化されました。 たくさんのプラグインがあり自由に機能を追加をすることができるため、開発ツールにおける共通プラットフォームとして位置づけられています。 Eclipse自体は、Javaで実装されています。

0グッド

0クリップ

投稿2018/06/24 11:45

前提・実現したいこと

質問です。

http://tech.pjin.jp/blog/2016/06/10/springframework8/
上記のサイトでspringの勉強をしており、
STSとMySQLの連携をしたいです。

発生している問題・エラーメッセージ

application-config.xmlを指示通り書き換えたところ、 Multiple annotations found at this line: - cvc-complex-type.2.4.a: Invalid content was found starting with element 'property'. One of '{"http:// www.springframework.org/schema/beans":description, "http://www.springframework.org/schema/beans":meta, "http:// www.springframework.org/schema/beans":bean, "http://www.springframework.org/schema/beans":ref, "http:// www.springframework.org/schema/beans":idref, "http://www.springframework.org/schema/beans":value, "http:// www.springframework.org/schema/beans":null, "http://www.springframework.org/schema/beans":array, "http:// www.springframework.org/schema/beans":list, "http://www.springframework.org/schema/beans":set, "http:// www.springframework.org/schema/beans":map, "http://www.springframework.org/schema/beans":props, WC[##other:"http:// www.springframework.org/schema/beans"]}' is expected. Multiple annotations found at this line: - Start tag of element <property> - cvc-complex-type.2.4.a: Invalid content was found starting with element 'property'. One of '{"http:// www.springframework.org/schema/beans":description, "http://www.springframework.org/schema/beans":meta, "http:// www.springframework.org/schema/beans":bean, "http://www.springframework.org/schema/beans":ref, "http:// www.springframework.org/schema/beans":idref, "http://www.springframework.org/schema/beans":value, "http:// www.springframework.org/schema/beans":null, "http://www.springframework.org/schema/beans":array, "http:// www.springframework.org/schema/beans":list, "http://www.springframework.org/schema/beans":set, "http:// www.springframework.org/schema/beans":map, "http://www.springframework.org/schema/beans":props, WC[##other:"http:// www.springframework.org/schema/beans"]}' is expected. Multiple annotations found at this line: - End tag of element <property> - The element type "bean" must be terminated by the matching end-tag "</ bean>". 以上の3つのエラーを吐いてしまいます。

該当のソースコード

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<!-- Uncomment and add your base-package here: <context:component-scan base-package="org.springframework.samples.service"> --> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource" > <property name="packagesToScan" value="jp.ssie.helloworld.model" > <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" > </property> <property name="jpaProperties"> <props> <prop key="hibernate.hbm2ddl.auto">none</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect </prop> </props> </property> </bean>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" >
<property name="url" value="${jdbc.url}" >
<property name="username" value="${jdbc.username}" >
<property name="password" value="${jdbc.password}" >
<property name="removeAbandoned" value="true" >
<property name="initialSize" value="3" >
<property name="maxActive" value="30" >
<property name="validationQuery" value="select now()" >
</bean>

<context:property-placeholder location="classpath:jdbc.properties" >

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="dataSource" > </bean> <bean id="namedParameterJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate"> <constructor-arg ref="dataSource" > </bean>

<jpa:repositories base-package="jp.ssie.helloworld.repository">

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" >
</bean>

<tx:annotation-driven >
</beans>

試したこと

終了タグなどがおかしいのかと思い、色々いじってみましたが、
application-config.xmlの書き方もよく分かっておらず、終了タグがいるものといらないものとあって
よく分かりませんでした。

補足情報(FW/ツールのバージョンなど)

macOS Sierra
STS 3.7.3.RELEASE

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

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

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

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

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

guest

回答1

0

ベストアンサー

xml

1<!-- Uncomment and add your base-

の前って</bean>欲しくないですか?
その後のEntityManagerのところで<bean>始まってるのでネストしてしまうのではないかと


あまり、xmlで設定書いてないので間違ってるかもしれないですが
質問にあった xmlをフォーマットかけてみたものを下に貼ります。
やっぱりDataSourceのプロパティ当たりのネストが深い気がしますが何かの参考になるでしょうか?

xml

1<?xml version="1.0" encoding="UTF-8"?> 2<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans 3http://www.springframework.org/schema/beans/spring-beans.xsd 4http://www.springframework.org/schema/jdbc 5http://www.springframework.org/schema/jdbc/spring-jdbc.xsd 6http://www.springframework.org/schema/data/jpa 7http://www.springframework.org/schema/data/jpa/spring-jpa.xsd 8http://www.springframework.org/schema/tx 9http://www.springframework.org/schema/tx/spring-tx-4.0.xsd 10http://www.springframework.org/schema/context 11http://www.springframework.org/schema/context/spring-context.xsd"> 12 <!-- 13 Uncomment and add your base-package here: 14 <context:component-scan 15 base-package="org.springframework.samples.service"> 16 --> 17 <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 18 <property name="dataSource" ref="dataSource"> 19 <property name="packagesToScan" value="jp.ssie.helloworld.model"> 20 <property name="jpaVendorAdapter"> 21 <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> 22 </bean> 23 <property name="jpaProperties"> 24 <props> 25 <prop key="hibernate.hbm2ddl.auto"> 26 none 27 </prop> 28 <prop key="hibernate.show_sql"> 29 true 30 </prop> 31 <prop key="hibernate.dialect"> 32 org.hibernate.dialect.MySQLDialect 33 </prop> 34 </props> 35 </property> 36 </property> 37 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> 38 <property name="driverClassName" value="${jdbc.driverClassName}"> 39 <property name="url" value="${jdbc.url}"> 40 <property name="username" value="${jdbc.username}"> 41 <property name="password" value="${jdbc.password}"> 42 <property name="removeAbandoned" value="true"> 43 <property name="initialSize" value="3"> 44 <property name="maxActive" value="30"> 45 <property name="validationQuery" value="select now()"> 46 </property> 47 <property-placeholder location="classpath:jdbc.properties"> 48 <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> 49 <property name="dataSource" ref="dataSource"> 50 </property> 51 <bean id="namedParameterJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate"> 52 <constructor-arg ref="dataSource"> 53 </constructor-arg> 54 <repositories base-package="jp.ssie.helloworld.repository"> 55 <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 56 <property name="entityManagerFactory" ref="entityManagerFactory"> 57 </property> 58 <annotation-driven> 59 </annotation-driven> 60 </bean> 61 </repositories> 62 </bean> 63 </bean> 64 </property-placeholder> 65 </property> 66 </property> 67 </property> 68 </property> 69 </property> 70 </property> 71 </property> 72 </bean> 73 </property> 74 </property> 75 </bean> 76</beans> 77

投稿2018/06/26 09:54

編集2018/06/26 12:35
euledge

総合スコア2404

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

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

y-baminami

2018/06/28 12:01

詳しい回答ありがとうございました。 原因は古い情報をみていたため、インストールするライブラリの名前が違っていたことでした。
silver-

2018/09/06 04:10

y-baminami様、はじめまして。 解決済みの投稿へのレス失礼いたします。 プログラミング初心者で同じサイトを使用して勉強しており、全く同じ3点のエラーで躓いております。 「インストールするライブラリの名前が間違っていた」とのことですが、具体的にどのように修正されたのでしょうか。 自分でライブラリ名などを調べてみておりますが、何分知識が至らず、ご教示いただけますと大変助かります。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問