Posts

Showing posts with the label spring

how to construct @service in Springboots using a payload variable

how to construct @service in Springboots using a payload variable I'm quite new in spring boots so I hope this is not a silly question I have a @Service that needs to initiate a class attribute, this attribute needs a information that comes from the RestPayload in the Controller. I'm not finding the most recommend way to do that. @RestController public class UserController { @Autowired private UserService userService; @RequestMapping("/searchUser") public List<UserWrapper> searchUser(@RequestBody UserWrapper userWrapper) { List<UserWrapper> returnUserWrapper = userService.findByName(userWrapper); return returnUserWrapper; } } And the service layer, I would like to be something like: @Service public class UserService { private LdapTemplate ldapTemplate; public static final String BASE_DN = "xxxxxxx"; @Value( value = "${sample.ldap.url}" ) private Str...

how to make common dead letter exchange to all my queues

how to make common dead letter exchange to all my queues I have a common library that handles all the configuration for the rabbitMQ and I'm aiming to achieve a common strategy to handle errors messages after certain attempts and what is in my mind have an exchange that receives all dead letter messages and will differentiate each message by having a header that has an originated queue name. this all after a number of attempts and retries. I have no idea how to implement this approach, your help to achieve this! here one of my lisnteners @RabbitListener(bindings = @QueueBinding( value = @Queue(value = "${swift.queue.driverOnlineStatus}", durable = "true"), exchange = @Exchange(value = "${swift.queue.driverExchange}", type = ExchangeTypes.HEADERS, ignoreDeclarationExceptions = "true"), arguments = { @Argument(name = "x-match", value = "all"), @Argum...

How to integrate Flyway into our spring-batch jdbc application

How to integrate Flyway into our spring-batch jdbc application We have a spring-batch application with DB2 jdbc data source. Want to add Flyway migration capabilities to our app. I've been exploring this article, it makes perfect sense, except the section that mentions how to specify the 'entityManagerFactory' - their example is for JPA with Hibernate,and it looks like this: <!-- Entity Manager Factory configuration --> <bean id="entityManagerFactory" class="o.s.orm.jpa.LocalContainerEntityManagerFactoryBean" depends-on="flyway"> <property name="dataSource" ref="dataSource" /> <property name="jpaVendorAdapter"> <bean class="o.s.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="database" value="${jpa.database}"/> </bean> </property> </bean> Our app is simple JDBC...

spring error No qualifying bean of type JdbcTemplate

spring error No qualifying bean of type JdbcTemplate I have a spring boot application where I am creating Datasource and JdbcTemplate manually in my config because I need to decrypt datasource password. Datasource JdbcTemplate I am using tomcat DataSource ( org.apache.tomcat.jdbc.pool.DataSource ) as recommended in spring boot docs since I am configuring connection properties. DataSource org.apache.tomcat.jdbc.pool.DataSource I am excluding autoconfiguration for datasource (see Application.java ) since I am creating one manually. Application.java Application.java // exclude datasourceAutoConfiguration since we are creating manaully creating datasource bean in AppConfig @SpringBootApplication @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) public class Application { public static void main(String args) { SpringApplication.run(Application.class, args); } } Here is my application.properties file application.properties jdbc.hostdb.url=jdbc:jtds:sq...

Why use Spring framework when we can achieve loosely coupled code using interfaces?

Why use Spring framework when we can achieve loosely coupled code using interfaces? As far as i know we use spring IOC so that it becomes easy for developer to check the xml file to identify and control the flow of code by providing the dependencies explicitly. But if we use autowire, developer actually has to check the code to identify which implementation is autowired to given class same thing could have been achieved without actually using spring framework for example, so why we need spring or what is the real advantage of using springs in this case. Interface Vehicle { ..... } Class Car implements Vehicle { ...... } Class Example { Vehicle v = new Car() } Or Class Example { @Autowire Vehicle v; .... } we use spring IOC so that it becomes easy for developer to check the xml file to identify and control the flow of code by providing the dependencies explicitly : no, not at all. It's been years since Spring apps don't use XML anymore, a...