When I try to read data from the database, at least using ((Session)em.getDelegate()).createCriteria() an exception is throws saying that a transaction is not present. When I add the annotation: it works fine. However, since reading will happen million of times per second to access and read data, I want to make sure that our environment is not clogged up unnecessarily.
Tag: spring
Immutable @ConfigurationProperties
Is it possible to have immutable (final) fields with Spring Boot’s @ConfigurationProperties annotation? Example below Approaches I’ve tried so far: Creating a @Bean of the MyProps class with two constructors Providing two constructors: empty and with neededProperty argument The bean is created with new MyProps() Results in the field being null Using @ComponentScan and @Component to provide the MyProps bean.
Spring Boot with container security
I’ve been using spring boot for some projects lately and I really like it. For a new project, we’d like to use tomcat-users.xml for really basic authentication, but I can’t figure out how to use the mechanism without a web.xml file. Most people using spring boot seem to be using spring security. Is it possible to use tomcat container security
How to log Spring Data JPA repository method execution time?
I have simple Spring Data JPA repository. Is there any way to monitor execution time for methods generated by Spring (for example findOne(…))? Answer The easiest way is to use a CustomizableTraceInterceptor as follows:
Spring Security 3 – always return error 302
I use Spring 4 to create a simple application. Recently, I’m adding Spring Security 3 to the project but always get the Error Code 302 ( so it redirect to home page always ). Here is my SecurityConfig: I have a Controller called AccountController: My WEB-INF structure: The flow is like: User access the web site with http://mylocal:8080/moon => it
Thymeleaf: how to use conditionals to dynamically add/remove a CSS class
By using Thymeleaf as template engine, is it possible to add/remove dynamically a CSS class to/from a simple div with the th:if clause? Normally, I could use the conditional clause as follows: We will be creating a link to the lorem ipsum page, but only if condition clause is true. I’m looking for something different: I’d like the block to
Spring JMS(ActiveMQ) delayed delivery of messages
We’re trying to set a delay on some JMS messages, so that a message will only be added to the queue/ received by the listener after x time. So far we’ve tried 2 approaches that didn’t work. 1) According to the spring documentation, we can set the delivery delay on the JMSTemplate. This is the sample code we tried: However,
Why does Hibernate throw org.hibernate.exception.LockAcquisitionException?
I have this method : Mapping : Person.hbm.xml Cars.hbm.xml This method works well for a single thread, and on multiple threads, gives me an error: AOP Transaction : NB : When i add Thread.sleep(5000) after update, it is ok. But this solution is not clean. Answer I have Cars -> (1 -n) places. And i have a foreign key in
Spring dynamically choosing between data sources (alternative to ThreadLocal)
I’ve read about AbstractRoutingDataSource and the standard ways to bind a datasource dynamically in this article: It uses a ThreadLocal context holder to “set” the DataSource: I have a quite complex system where threads are not necessarily in my control, say: Scheduled EJB reads a job list from the database For each Job it fires a Spring (or Java EE)
How to convert a multipart file to File?
Can any one tell me what is a the best way to convert a multipart file (org.springframework.web.multipart.MultipartFile) to File (java.io.File) ? In my spring mvc web project i’m getting uploaded file as Multipart file.I have to convert it to a File(io) ,there fore I can call this image storing service(Cloudinary).They only take type (File). I have done so many searches