タグ付けされた質問 「spring」

Spring Frameworkは、Javaプラットフォームでのアプリケーション開発のためのオープンソースフレームワークです。中核となるのは、コンポーネントベースのアーキテクチャに対する豊富なサポートであり、現在、20を超える高度に統合されたモジュールを備えています。


9
Spring構成ファイルでBeanのプロパティに列挙値を割り当てる方法は?
次のようなスタンドアロンの列挙型が定義されています。 package my.pkg.types; public enum MyEnumType { TYPE1, TYPE2 } 次に、その型の値をBeanプロパティに挿入します。 <bean name="someName" class="my.pkg.classes"> <property name="type" value="my.pkg.types.MyEnumType.TYPE1" /> </bean> ...そしてそれはうまくいきませんでした:( 列挙型をSpring Beanに注入するにはどうすればよいですか?
109 java  spring 


8
同じクラス内のメソッドによるSpring @Transactionメソッド呼び出し、機能しませんか?
Spring Transactionは初めてです。私が本当に奇妙だと思った何か、おそらく私はこれを正しく理解しました。 メソッドレベルのトランザクションを使用したいと思っていて、同じクラス内に呼び出し側メソッドがあり、それが好きではないようです。別のクラスから呼び出す必要があります。どうしてそれが可能か分かりません。 誰かがこの問題を解決する方法を知っているなら、私は非常に感謝します。同じクラスを使用して、注釈付きトランザクションメソッドを呼び出したいと思います。 これがコードです: public class UserService { @Transactional public boolean addUser(String userName, String password) { try { // call DAO layer and adds to database. } catch (Throwable e) { TransactionAspectSupport.currentTransactionStatus() .setRollbackOnly(); } } public boolean addUsers(List<User> users) { for (User user : users) { addUser(user.getUserName, user.getPassword); } …

9
Springブートアプリケーションでフィールド:RestTemplateを自動配線できませんでした
起動時にスプリングブートアプリケーションを実行すると、例外が発生します。 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.web.client.RestTemplate com.micro.test.controller.TestController.restTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.web.client.RestTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. …

2
application.ymlは環境変数をサポートしていますか?
私はapplication.yml設定で環境変数を使用してみました: spring: main: show_banner: false --- spring: profiles: production server: address: $OPENSHIFT_DIY_IP port: $OPENSHIFT_DIY_PORT しかし、env変数は解決されません。別の表記を指定する必要がありますか? Railsでは、たとえば<%= ENV ['FOOVAR']%>を使用できます。 唯一の選択肢は、次のようにアプリを実行することです: java -jar my.jar --server.address=$OPENSHIFT_DIY_IP --server.port=$OPENSHIFT_DIY_PORT
109 java  spring  yaml  spring-boot 

1
Spring @Configurationクラスを理解する
Spring @Autowiredの使い方を理解するという質問に続いて、スプリングワイヤリングの他のオプションである@Configurationクラスの完全なナレッジベースを作成したいと考えました。 次のようなSpring XMLファイルがあるとします。 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <import resource="another-application-context.xml"/> <bean id="someBean" class="stack.overflow.spring.configuration.SomeClassImpl"> <constructor-arg value="${some.interesting.property}" /> </bean> <bean id="anotherBean" class="stack.overflow.spring.configuration.AnotherClassImpl"> <constructor-arg ref="someBean"/> <constructor-arg ref="beanFromSomewhereElse"/> </bean> </beans> @Configuration代わりにどのように使用できますか?コード自体に影響はありますか?

30
このアプリケーションには/ errorの明示的なマッピングがありません
Mavenを使用してチュートリアルを実行しましたhttps://spring.io/guides/gs/uploading-files/ 使用したすべてのコードがコピーされました。 アプリケーションは実行できますが、エラーが発生します。 ホワイトラベルエラーページこのアプリケーションには/ errorの明示的なマッピングがないため、これはフォールバックと見なされます。6月30日火曜日17:24:02 CST 2015予期しないエラーが発生しました(type = Not Found、status = 404)。メッセージはありません どうすれば修正できますか?

3
Spring MVCのインターセプターとフィルターの違い
FilterとInterceptor目的について少し混乱しています。 ドキュメントから理解したInterceptorように、リクエスト間で実行されます。一方、Filterビューをレンダリングする前に実行されますが、コントローラーが応答をレンダリングした後です。 ではpostHandle()、インターセプターとdoFilter()フィルターの違いはどこですか? どのユースケースで使用するのがベストプラクティスですか?この写真FilterのsとInterceptorsはどこで機能しますか?

13
Hibernate LazyInitializationExceptionを修正する方法:ロールのコレクションを遅延初期化できませんでした、プロキシを初期化できませんでした-セッションがありません
SpringプロジェクトのカスタムAuthenticationProviderで、ログに記録されたユーザーの権限のリストを読み取ろうとしていますが、次のエラーが発生します。 org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.horariolivre.entity.Usuario.autorizacoes, could not initialize proxy - no Session at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:566) at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:186) at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:545) at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:124) at org.hibernate.collection.internal.PersistentBag.iterator(PersistentBag.java:266) at com.horariolivre.security.CustomAuthenticationProvider.authenticate(CustomAuthenticationProvider.java:45) at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:156) at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:177) at org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter.attemptAuthentication(UsernamePasswordAuthenticationFilter.java:94) at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:211) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:57) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) …


13
Spring BootのデフォルトのH2 JDBC接続(およびH2コンソール)
私は単に、application.propertiesで何も指定せず、mvn spring:runで開始すると、spring-bootが作成する組み込みH2データベースのH2データベースコンテンツを表示しようとしています。hibernate JPAがテーブルを作成しているのを確認できますが、データベースの下のURLでh2コンソールにアクセスしようとすると、データベースにテーブルがありません。 http://localhost:8080/console/ 次のような提案が 表示されます。Springによって開始された埋め込みH2データベースのコンテンツを表示します しかし、提案されたXMLをスプリングブートのどこに配置すればよいかわからないので、外部データベースが構成されているときにh2consoleを使用可能にしたくないので、これを処理する必要がある可能性が高くなります。ある種の条件付きコードを使用する(または、Mavenプロファイルがアクティブ化されているときにH2のみを含める最も理想的なケースでは、Springが自動的に処理できるようにする)。 ブート時にH2コンソールを機能させる方法(およびSpringが使用しているjdbc接続文字列を確認する方法)を示すサンプルコードはありますか?
107 java  spring  jpa  h2  spring-boot 

18
インターネット接続がない場合、Spring schemaLocationが失敗する
私はSpringを使用しapplication-context.xmlており、次の定義があります: <?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:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" xmlns:security="http://www.springframework.org/schema/security" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.xsd" > ..... インターネット接続が失われると、tomcatまたはjetty経由でアプリケーションを実行できません。 それは与えます: [main] WARN org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Ignored XML validation warning org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document '/spring-beans-2.0.xsd', because 1) could not …
107 java  xml  spring  xsd 

16
YAMLを使用したSpring @PropertySource
Spring Bootを使用すると、application.propertiesファイルを同等のYAMLに置き換えることができます。しかし、私は私のテストで障害にぶつかったようです。私TestConfiguration(簡単なJava設定)に注釈を付けると、プロパティファイルが必要になります。 たとえば、これは機能しません: @PropertySource(value = "classpath:application-test.yml") YAMLファイルにこれがある場合: db: url: jdbc:oracle:thin:@pathToMyDb username: someUser password: fakePassword そして、私はこれらの値を次のようなもので活用します: @Value("${db.username}") String username しかし、私はそのようにエラーになってしまいます: Could not resolve placeholder 'db.username' in string value "${db.username}" テストでもYAMLの良さを活用するにはどうすればよいですか?

7
Spring BootがHTTPリクエストインターセプターを追加する
Spring BootアプリケーションにHttpRequestインターセプターを追加する正しい方法は何ですか?私がやりたいことは、すべてのhttp要求の要求と応答をログに記録することです。 Spring bootのドキュメントには、このトピックはまったく含まれていません。(http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/) 以前のバージョンのSpringで同じことを行う方法に関するWebサンプルをいくつか見つけましたが、それらはapplicationcontext.xmlで動作します。助けてください。

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.