I need to fetch a property with the following format:
${/a/env/mode}
However this depends on where im deployed, I have all the required information in configuration already and is trying to use the following:
${/a/${env}/${mode}}
This is not working as expected in Spring Boot but instead gives an exception. Is there anyway to get what I need?
Related
I am trying to use spring config server to load additional properties on my application.
I would like to be able to use #Value annotation on field to load values from config server file but i don't know why it doesn't work. I am using version 1.2.0 of spring cloud config client and io.spring.platform-2.0.8 (becouse i have Spring MVC, not springboot here)
Exception I am getting is just IllegalArgumentException and message is about placeholder that cannot be found. When i try to get this property via org.springframework.core.env.Environment.getProperty(propertyName) everything works fine and the value is simply recognized so i dunno why #Value doesn't work
We are modernizing one of our applications and we decided to use Spring Boot together with Apache Camel.
One of the configuration files from old version has something like this:
<camel:threadPoolProfile id="myThreadPoolProfile"
poolSize="10" maxPoolSize="20" maxQueueSize="1000" rejectedPolicy="DiscardOldest" />
What I saw in camel documentation on this link is that there is possibility to configure basically the same thing we have in old version. But then I got stuck on id field. It's missing, but there is property camel.threadpool.config which explanation sounds something I need (Adds a configuration for a specific thread pool profile (inherits default values)), but so far I am struggling to make a use of it. I tried something like this:
camel:
threadpool:
pool-size: 10
max-pool-size: 20
max-queue-size: 1000
rejected-policy: discardoldest
config:
id: "myThreadPoolProfile"
I am getting following error:
Description:
Failed to bind properties under 'camel.threadpool.config.id' to org.apache.camel.spring.boot.threadpool.CamelThreadPoolConfigurationProperties$ThreadPoolProfileConfigurationProperties:
Reason: No converter found capable of converting from type [java.lang.String] to type [org.apache.camel.spring.boot.threadpool.CamelThreadPoolConfigurationProperties$ThreadPoolProfileConfigurationProperties]
I guess I don't understand how this spring boot configuration works.
Ok I found an answer, or better to say example here. So the syntax for what I was trying to do would be following:
camel:
threadpool:
pool-size: 10
max-pool-size: 20
max-queue-size: 1000
rejected-policy: discardoldest
config[myThreadPoolProfile]:
id: "myThreadPoolProfile"
If you carefully notice the error you are trying to map String to Properties(Map).
See below there is no such property available in configuration map hence its failing.
I have also checked in detail with latest javadoc for the same class. You can refer the same to check what all fields are available.
https://javadoc.io/doc/org.apache.camel.springboot/camel-spring-boot/latest/org/apache/camel/spring/boot/threadpool/CamelThreadPoolConfigurationProperties.ThreadPoolProfileConfigurationProperties.html
Below are the available properties in spring boot camel starter.
https://camel.apache.org/camel-spring-boot/latest/spring-boot.html
I am trying to disable Redis when I am testing with spring boot. I have disabled my configuration but the auto config created a default connection and fails because it can't connect to a non-existent service. For testing I am content to just use a basic in-memory cache or a no-op cache. That doesn't work either. Here is what I have tried:
per this issue I added said configuration to my test app properties
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
But. That gets me a bit further. But ultimately I get a NoSuchBeanDefinitionException redisTemplate - this is because redisReferenceResolver is trying to look that up.
Looking at my debugger right now, the bean it's trying to hydrate is:
org.springframework.data.redis.core.convert.ReferenceResolverImpl which is coming from spring-data-redis:1.8.0.RELEASE which is coming from this dependency: compile('org.springframework.boot:spring-boot-starter-data-redis') . I admit, the bean name is a bit misleading. The type it actually resolves to is not
The only other reference to redis is in our hibernate support.
Can someone explain how to turn this off for testing?
Try excluding this two auto-configuration classes in your test properties file:
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration
or
exclude
org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
and set: spring.data.redis.repositories.enabled=false
With YAML syntax (& Spring Boot):
spring.autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
- org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration
If you have SystemEnvironmentPropertySource in you app context you can use environment variable SPRING_AUTOCONFIGURE_EXCLUDE separating items with comma:
SPRING_AUTOCONFIGURE_EXCLUDE=org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration
Also try #EnableAutoConfiguration(exclude = {...}) on a #TestConfiguration annotated class.
If you dont want to change any files/code, you can also do this with an environment variable:
SPRING_AUTOCONFIGURE_EXCLUDE=org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration
I'm using Spring boot with a H2 database for local dev work, the problem being encountered is with a domain class that I initially setup. It worked fine but I then renamed a property and now I receive the error "java.lang.IllegalArgumentException: No property name found for type class org.rest.model.Foo"
I think the cause is that the Spring auto configuration has scanned the Domain class but hasn't detected that the property is now different and it's throwing the error.
How can I avoid this from happening as I have a number of changes that I'm implementing as I go?
I'm very new to Spring, but I am working on a project which is using Spring Data JPA to generate repositories for JPA entities.
I'm currently adding a simple module to be able to show some data on a webpage. I have added a Servlet, but I am having trouble accessing the repositories from there.
I have added a ContextLoaderListener in web.xml, I'm referencing the jpa:repositories and persistence.xml in the applicationContext.xml, but I'm currently stuck with this exception:
No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 0.
But when I add an EntityManagerFactory in persistence.xml I get the following cryptic message:
java.lang.IllegalAccessError: tried to access field
org.hibernate.engine.spi.CascadeStyle.STYLES from class
org.hibernate.engine.spi.EJB3CascadeStyle
My question is: is what I am trying to do even possible? And if so, how?
Or should I just bite the bullet and use Spring MVC or something else entirely?
Note: this is just for a one-page web site and I'm trying to keep it as simple as possible.
In order to use Spring Data JPA you need to configure the underlying JPA implementation as you would typically do in Spring, see for example, infrastructure.xml and META-INF/persistence.xml in spring-data-jpa-showcase (since Spring 3.1 you can get rid of persistence.xml if you use packagesToScan property of LocalContainerEntityManagerFactoryBean).
Your second problem with IllegalAccessError looks like a classloading problem caused by presence of different versions of Hibernate jars in classpath.