spring-annotations

Difference between Spring annotations

泪湿孤枕 提交于 2020-01-19 04:33:48
问题 Questions: 1) Difference between @Component and @Configuration ? I have read that both remove the necessity of wiring code to be put in XML, but did not get the difference between these. 2) What are the differences between @Autowired , @Inject and @Resource ? - Which one to use when? - What are the pros/cons of each? 回答1: @Component and @Configuration are indeed very different types of annotations. @Component and similar annotations ( @Service , @Repository , etc. )and its JSR-330 counterpart

indexing document to a specific collection using spring data solr

▼魔方 西西 提交于 2020-01-15 09:04:54
问题 I am trying to index a document to a specific collection in solr. The collection name is 'program'. I am using spring data solr. I am getting the below error when trying to save the document: HTTP ERROR 404 Problem accessing /solr/update. Reason:Not Found My assumption is that the annotation @SolrDocument is not recognized. spring-data-solr is trying to post the document to /solr/update whereas it should try to post it to /solr/program/update.However I am not sure how to prove it or fix it.

@Transient annotation, @org.springframework.data.annotation.Transient annotation, transient keyword and password storing

北城以北 提交于 2020-01-10 10:13:25
问题 Currently I'm learning the Spring framework, mainly focusing on it's Security Module. I've watched some guides in connection with registration and login. I saw this common usage of transient keyword or @Transient annotation on the password field in the User class. My dummy app is using Spring Boot + Spring MVC + Spring Security + MySQL. I know that Java's transient keyword is used to denote that a field is not to be serialized. JPA's @Transient annotation ... ...specifies that the property or

@Transient annotation, @org.springframework.data.annotation.Transient annotation, transient keyword and password storing

北慕城南 提交于 2020-01-10 10:13:09
问题 Currently I'm learning the Spring framework, mainly focusing on it's Security Module. I've watched some guides in connection with registration and login. I saw this common usage of transient keyword or @Transient annotation on the password field in the User class. My dummy app is using Spring Boot + Spring MVC + Spring Security + MySQL. I know that Java's transient keyword is used to denote that a field is not to be serialized. JPA's @Transient annotation ... ...specifies that the property or

Injection of autowired dependencies failed

回眸只為那壹抹淺笑 提交于 2020-01-06 03:33:12
问题 I'm trying to realize the same as in Spring error when trying to manage several classes that share a common base class? But I'm still getting this Exception: Error creating bean with name 'com.example.model.CategoryTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.example.model.CategoryService com.example.model.CategoryTest.service; nested exception is org.springframework.beans

Spring cache using memcached

不想你离开。 提交于 2020-01-05 07:31:09
问题 I'm using https://github.com/AKQABER/simple-spring-memcached to have memcached integrated as a cache implementation with spring. But I'had no success :P I'm using spring 4 and spring-data-jpa public interface FooRepository extends JpaRepository<Foo, Long> { @Cacheable(value = "defaultCache", key = "lala") Foo findByNameAndDescription(String name, String description); } I hardcoded the key for test purposes. Nothing special, use a cache called "defaultCache". The configuration of memcached is:

What is the meaning and what it does autowire=“default” in spring in applicationcontext.xml file

筅森魡賤 提交于 2020-01-04 14:07:13
问题 What is the meaning of autowire="default" and what it does if autowire="default" in applicationcontext.xml file Example code Snippet - <beans> <bean name="aa" class="Address"> </bean> <bean id="person" class="Person" autowire="default"> </bean> </beans> 回答1: That the autowiring is not performed. autowire="default" is the same as putting autowire="no", which is: no – Default, no auto wiring, set it manually via “ref” attribute source: http://www.mkyong.com/spring/spring-auto-wiring-beans-in

How do I perform Constructor-based dependency injection with Spring using annotations?

血红的双手。 提交于 2020-01-04 01:53:08
问题 OK, so if I need to put some primitive values in the constructor, how do I do that? @Autowired public CustomBean(String name, @Qualifier("SuperBean") SuperBean superBean) { super(); this.superBean = superBean; this.name = name; } For instance here I am defining that the superBean has the Qualifier "SuperBean", but I'd also like to know how is it possible to use annotations to set the name value here? I know it's possible with xml configuration, but I want to know how to do this with

How to unit test Spring IntegrationFlow?

微笑、不失礼 提交于 2020-01-03 19:07:10
问题 I have been using Spring Integration DSL to implement some messaging processing flow. How can I actually unit test a single IntegrationFlow, can anyone provide me with an example on how to unit test i.e. transform part of this bean: @Bean public IntegrationFlow transformMessage(){ return message -> message .transform(new GenericTransformer<Message<String>, Message<String>>() { @Override public Message<String> transform(Message<String> message) { MutableMessageHeaders headers = new

@AutoConfigureAfter not working as desired

本小妞迷上赌 提交于 2020-01-03 17:55:08
问题 I have 3 spring-boot-starter projects One of the autoconfiguration class has the following code: @Configuration @ConditionalOnClass(value = Config.class) @AutoConfigureAfter(value = {FileGeneratorConfig.class, FileUploaderConfig.class}) public class JobConfig FileGeneratorConfig and FileUploaderConfig are also autoconfiguration classes. I was expecting that beans created in FileUploaderConfig will be created first. So test this I had put a break point in the method that creates bean in