spring-projects | Spring integrates redis , spring mvc realizes session | Microservice library
kandi X-RAY | spring-projects Summary
kandi X-RAY | spring-projects Summary
Spring integrates redis, spring mvc realizes session sharing and redis leaderboard
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Set session object .
- wrapper around method .
- Set session .
- Get list by key
- Get hash value .
- Returns a string representation of this User object .
- Handle the index
- The property name .
- Gets the id .
- Returns the amount of money in this exchange .
spring-projects Key Features
spring-projects Examples and Code Snippets
@Bean
public HiddenHttpMethodFilter hiddenHttpMethodFilter() {
return new HiddenHttpMethodFilter() {
@Override
public Mono filter(ServerWebExchange exchange, WebFilterChain chain) {
return chain.fil
Community Discussions
Trending Discussions on spring-projects
QUESTION
I am using Spring Boot 2.4.4
and Spring Data Cassandra dependency to connect to the Cassandra database. During the application startup, I am getting a DriverTimeout error (I am using VPN).
I have gone through all the Stack Overflow questions similar to this and none of them worked for me. I have cross-posted the same question on the Spring Boot official page here.
I used below configuration properties below -
...ANSWER
Answered 2021-Apr-23 at 08:35The DriverTimeoutException
gets thrown when the driver doesn't get a reply from the coordinator node. It uses the basic request timeout default of 2 seconds:
QUESTION
is there a way to perform insertion of an @Id
-column value into a non @Id
column when entity is being created/updated to avoid double-save
-ing?
ANSWER
Answered 2021-Jun-08 at 11:59@GeneratorType allows to generate/set values into entity during insertion phase. Suppose your entity looks like this:
QUESTION
I am doing a study on the feasibility of a Spring Batch composed of two datasources. A SQL datasource for the Spring Batch metadata and a MongoDB datasource (with transactional use) for the business data. The transactional aspect raises several questions here.
The following topic: Spring batch with MongoDB and transactions and related resources provide a number of answers to my questions.
The answer mentions the use of Spring's JtaTransactionManager
to manage distributed transactions on the two datasources.
This technique uses the 2PC protocol. It is also the most robust solution if I understood correctly. https://www.infoworld.com/article/2077963/distributed-transactions-in-spring--with-and-without-xa.html?page=2
On the other hand, I found some resources about Spring's ChainedTransactionManager
. This technique uses the best effort 1PC protocol. This solution is less robust, if I understand correctly the system can be in an inconsistent state in case of a problem in the infrastructure (network failure for example).
The ChainedTransactionManager
has the advantage of being easier to implement and offers better performance. I saw that it is deprecated https://github.com/spring-projects/spring-data-commons/issues/2232.
What are the concrete risks of using the ChainedTransactionManager
in a Spring Batch? In case of an error, can I have inconsistencies between the Spring batch metadata and the business data in Mongo?
I imagine there are also considerations to take into account with retry or chunk skip strategies?
Thanks a lot for your help.
...ANSWER
Answered 2021-Jun-07 at 12:58In case of an error, can I have inconsistencies between the Spring batch metadata and the business data in Mongo?
Yes, that's is the risk you should be aware of.
A common technique to avoid that is to disable state management and use the process indicator pattern. You can find an example here.
QUESTION
I'm trying to write a generic function to do some Webflux operations and I'm getting a class cast exception that I can't figure out
...ANSWER
Answered 2021-Jun-05 at 18:24This works so you're probably not getting a ViewModel
back from your webClient body but rather the map
of parameters (or something) from the ViewModel
.
QUESTION
I'm working on Windows 10 pro, Java 1_8 or Java 1_15. No corporate proxy, connectivity to the internet works just fine.
I'm trying to build spring-boot from the source. I cloned the github repo, then checked out the tag that I needed.
...ANSWER
Answered 2021-Jun-02 at 17:35The message about the build scan can be ignored. A build scan describes what happened during the build and isn’t needed to access the build’s output.
When you run build
, each module’s jar is written to its build/libs
directory. For example, you’ll find the jar for the spring-boot
module in spring-boot-project/spring-boot/build/libs
. Alternatively, you may want to run publishToMavenLocal
. It will publish each module to your local Maven cache from where you can consume it in a Maven build, or a Gradle build configured with mavenLocal()
as a repository.
QUESTION
Recently we run a test which created different Spring batch job instances concurrently (e.g 10 threads in parallel, job names are similar but different, e.g with the same prefix). And it's fairly easy to trigger deadlockerror reported from MySQL exception is
org.springframework.dao.DeadlockLoserDataAccessException: PreparedStatementCallback; SQL [INSERT into BATCH_JOB_INSTANCE(JOB_INSTANCE_ID, JOB_NAME, JOB_KEY, VERSION) values (?, ?, ?, ?)]; Deadlock found when trying to get lock; try restarting transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:267) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1443) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:633) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:862) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:917) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:922) at org.springframework.batch.core.repository.dao.JdbcJobInstanceDao.createJobInstance(JdbcJobInstanceDao.java:120) at org.springframework.batch.core.repository.support.SimpleJobRepository.createJobExecution(SimpleJobRepository.java:140) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
We searched for existing reports regarding to deadlock and find that some are specific to SQLServer like this: (https://github.com/spring-projects/spring-batch/issues/1448). After analysis of the isolation level used for creating jobs(SERIALIZABLE) and the operation sequence, we think the deadlock could be trigged as following:
1、before creating a job instance, the code will first query batch_job_instance table to check if the instance already exists(about 3 times), under SERIALIZABLE mode, this will hold shared next-key lock (https://dev.mysql.com/doc/refman/5.7/en/innodb-next-key-locking.html) in MySQL which lock records that are in scope related to the job name.
2、thread 2 want to create job2 and insert a row in batch_job_instance and thread 3 want to do the same thing, as both threads hold the same read next-key lock and the rows that need to be inserted are also in the key scope, the deadlock will happen.
Refer to the link here(https://docs.spring.io/spring-batch/trunk/apidocs/org/springframework/batch/core/repository/support/AbstractJobRepositoryFactoryBean.html#setIsolationLevelForCreate-java.lang.String-), we tried changing the isolation level to REPEATABLE_READ and this worked without any deadlock.
So the key question here is :
Is setting isolation level to REPEATABLE_READ the recommended solution here and is there any side effect of this solution as it's not set as default option ?
Thanks a lot!
...ANSWER
Answered 2021-May-28 at 13:08we tried changing the isolation level to REPEATABLE_READ and this worked without any deadlock.
So the key question here is : Is setting isolation level to REPEATABLE_READ the recommended solution here and is there any side effect of this solution as it's not set as default option ?
Yes, that's the way to go. If SERIALIZABLE is too aggressive, you can use a less aggressive isolation level for the job repository. That's why the setIsolationLevelForCreate
is provided. This is actually documented in its Javadoc:
QUESTION
we plan to use Spring Batch for mission critical production batching system. And I am wondering which version we should choose now?
From the version history in github(https://github.com/spring-projects/spring-batch/tags): version 4.2.7 is marked with .RELEASE, while 4.3.3 is not.
So the questions are:
1、what's the difference regarding the versions with or without .RELEASE ending, is the ".RELEASE" ending verison more stable?
2、which version is recommended for production now ?
Thanks a lot!
ANSWER
Answered 2021-May-27 at 08:33Both are production ready releases, one for the 4.2 line and the other for the 4.3 line. I recommend using the latest 4.3 as it has an extended support lifetime. Spring Batch follows the same support terms as Spring Boot, and each version will be supported as long as the latest Spring Boot version that brings it is supported, see https://github.com/spring-projects/spring-boot/wiki/Supported-Versions.
For example:
- the latest Spring Boot version that brings Spring Batch 4.2 is 2.3 which will be OSS supported until May 2021.
- The latest Spring Boot version that brings Spring Batch 4.3 is 2.5 which will be OSS supported until May 2022.
- etc
Spring Boot 2.6 is expected on November 2021 and will likely bring Spring Batch 4.3 as well, which extends the OSS support for Spring Batch 4.3 for another year. So I recommend using the latest version from 4.3 to benefit from a longer support period since you are planning to use it in production. FTR, there is an ongoing effort to update the website/wiki with all these support details across the portfolio, so keep tuned.
In regard to the version name scheme, we (the Spring engineering team) have decided to switch from the old naming scheme (.BUILD-SNAPSHOT
, .RELEASE
, etc) to a new naming scheme. This has been announced on our blog here: Updates to Spring Versions.
QUESTION
I'm using spring-amqp's (latest version) rabbitTemplate.sendAndReceive(exchange, routingKey, message)
method for sending messages. RabbitTemplate is configured with Jackson2JsonMessageConverter.
If I send a malformed json, I can see that message conversion fails with org.springframework.amqp.support.converter.MessageConversionException: Failed to convert Message content
, as expected.
However, the sendAndReceive method doesn't abort and continues execution until a replyTimeout is hit. To compare, if there is an error in my @RabbitListener annotated method, then sendAndReceive aborts instantly and returns the exception.
Is there any way to tell spring to abort sendAndReceive in case of conversion exceptions?
...ANSWER
Answered 2021-May-19 at 19:35OK. I see what is going on. We fail on the AbstractMessageListenerContainer
which does not know yet that our MessageListener
is about a request-reply behavior. So, it silently handles an exception via its default ConditionalRejectingErrorHandler
, which, in turn, throws an AmqpRejectAndDontRequeueException
and that's it. The listener container comes back to the main loop for the next message.
You probably have to implement your own ConditionalRejectingErrorHandler
overriding its:
QUESTION
In my Spring batch job, I'm trying to share data between steps using JobExecutionContext, which works only if i keep the steps single threaded as follows:
...ANSWER
Answered 2021-May-17 at 08:31I'm trying to share data between steps using JobExecutionContext, which works only if i keep the steps single threaded
Relying on the execution context to share data between multi-threaded steps is incorrect, because the keys will be overridden by concurrent threads. The reference documentation explicitly mentions to turn off state management in multi-threaded environment:
- Javadoc:
remember to use saveState=false if used in a multi-threaded client
- Reference doc:
it is not recommended to use job-scoped beans in multi-threaded or partitioned steps
That said, I don't see what key could be shared from a multi-threaded step to the next step (as threads are executed in parallel), but if you really need to do that, you should use another method like defining a shared bean that is thread safe.
QUESTION
I am using Spring Data MongoDB and I have this simple repository:
...ANSWER
Answered 2021-May-10 at 13:34You are misinterpreting the code.
This line defines the primary query getting executed:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install spring-projects
You can use spring-projects like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the spring-projects component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page