spring-java-config

Send emails with Spring by using Java annotations

微笑、不失礼 提交于 2019-12-03 00:24:55
How could I send an email with Spring 4 (and Spring Boot ) by using a pure annotation-based approach (according to the Java Configurations rules)? A simple solution (where you will be using an SMTP server with no authentication) for configuring the email service would by @Configuration public class MailConfig { @Value("${email.host}") private String host; @Value("${email.port}") private Integer port; @Bean public JavaMailSender javaMailService() { JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl(); javaMailSender.setHost(host); javaMailSender.setPort(port); javaMailSender

spring autowired aop circular dependency

蓝咒 提交于 2019-12-02 18:07:53
I'm using java config with @ComponentScan in order to initialize my beans and @EnableAspectJAutoProxy(proxyTargetClass=true) to use cglib proxies. In this project we have a lots of generated services autowired between them using @Autowired . It works pretty well. But, for some of these services I've added @Async (I've also added @EnableAsync(proxyTargetClass = true) on my @Configuration class). After that, I'm getting: Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'ConversationUserLocalService': Bean with name

Spring Batch - How to generate parallel steps based on params created in a previous step

爷,独闯天下 提交于 2019-12-02 17:30:34
问题 Introduction I am trying to use jobparameters created in a tasklet to create steps following the execution of the tasklet. A tasklet tries to finds some files (findFiles()) and if it finds some files it saves the filenames to a list of strings. In the tasklet I pass the data as following: chunkContext.getStepContext().getStepExecution().getExecutionContext().put("files", fileNames); The next step is a parallel flow where for each file a simple reader-processor-writer step will be executed (if

How get working @Value or Environment in a class implementing the Condition/ConfigurationCondition interfaces

六月ゝ 毕业季﹏ 提交于 2019-12-02 11:06:36
问题 I am working with only JavaConfig. I have the following declaration: @Bean public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() { return new PropertySourcesPlaceholderConfigurer(); } it is mandatory for JavaConfig according with the following post: Spring 3.2 @value annotation with pure java configuration does not work, but Environment.getProperty works The following code works perfect (many @Values by testing purposes): @Configuration public class

Spring Batch - How to generate parallel steps based on params created in a previous step

旧街凉风 提交于 2019-12-02 08:55:34
Introduction I am trying to use jobparameters created in a tasklet to create steps following the execution of the tasklet. A tasklet tries to finds some files (findFiles()) and if it finds some files it saves the filenames to a list of strings. In the tasklet I pass the data as following: chunkContext.getStepContext().getStepExecution().getExecutionContext().put("files", fileNames); The next step is a parallel flow where for each file a simple reader-processor-writer step will be executed (if you are interested in how I got there please see my previous question: Spring Batch - Looping a reader

How get working @Value or Environment in a class implementing the Condition/ConfigurationCondition interfaces

▼魔方 西西 提交于 2019-12-02 07:26:57
I am working with only JavaConfig. I have the following declaration: @Bean public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() { return new PropertySourcesPlaceholderConfigurer(); } it is mandatory for JavaConfig according with the following post: Spring 3.2 @value annotation with pure java configuration does not work, but Environment.getProperty works The following code works perfect (many @Values by testing purposes): @Configuration public class ActiveMQServerConfiguration { @Value("${localhost.address}") private String localHost; @Value("${remotehost.address}"

springSecurityFilterChain nullPointer Exception

空扰寡人 提交于 2019-12-01 23:31:06
When I try to run project, the Tomcat return an exception. Some one can help with this problem? Configuration class: https://github.com/intrade/inventory/blob/master/src/main/java/com/springapp/mvc/InitApp/SecurityConfig.java Stack trace: Jan 24, 2014 4:09:40 PM org.apache.catalina.core.ApplicationContext log org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Instantiation of bean failed; nested

PropertySource not available during ConditionalOnExpression evaluation

筅森魡賤 提交于 2019-12-01 22:22:49
I have this following component class which I'd like to instantiate depending on a property; @Component("componentA") @PropertySource("classpath:components.properties") @ConditionalOnExpression("'${components.enabled}'.contains('componentA')") public class ComponentA implements ComponentIF { ... components.properties file has the following property; components.enabled=componentA,componentB,componentD The problem is that @PropertySource("classpath:components.properties") seems to be not available during the evaluation of @ConditionalOnExpression("'${components.enabled}'.contains('componentA')")

Could not obtain transaction-synchronized Session for current thread

点点圈 提交于 2019-12-01 17:27:50
I am getting the following Exception with a Spring4/Hibernate4 project I converted from xml- to Java-Config. org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread The project starts up property and errorfree in Eclipse, but on the first request the Exception appears. In my ConfigRoot -class I have @Bean configured for DataSource , SessionFactory , HibernateTransactionManager , ImprovedNamingStrategy . All my @Service services are annotated with @Transactional . Any idea where this could come from ? Edit 1 As requested, here the stacktrace: org

Could not obtain transaction-synchronized Session for current thread

流过昼夜 提交于 2019-12-01 16:27:13
问题 I am getting the following Exception with a Spring4/Hibernate4 project I converted from xml- to Java-Config. org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread The project starts up property and errorfree in Eclipse, but on the first request the Exception appears. In my ConfigRoot -class I have @Bean configured for DataSource , SessionFactory , HibernateTransactionManager , ImprovedNamingStrategy . All my @Service services are annotated with