I am trying to deploy a springboot application on kubernetese. I have stored all environment variable in config map and trying to read value from there. There are certain properties where we need to read int values.
In our code, it looks something like this :
application.properties :
TOKEN_RETRY_COUNT=3
As we have to read it from ConfigMap, we have updated our application.properties as mentioned below:
Update application.properties :
TOKEN_RETRY_COUNT=${STARGATE_TOKEN_RETRY_LIMIT}
Config Maps
The values are configured are like this in the Config Maps. I had to put double quotes as it wasn't allowed without any quote.
"STARGATE_TOKEN_RETRY_LIMIT": "3",
Now, when I am trying to read these values after deploying it on kubernetese, I am getting below error :
For STARGATE_TOKEN_RETRY_LIMIT :
Failed to convert value of type 'java.lang.String' to required type 'int'; nested exception is java.lang.NumberFormatException: For input string: "STARGATE_TOKEN_RETRY_LIMIT"
For now, I had updated code to take this value as String and then parse it as int but this is not ideal way. There should be some standard way to take different types.
If we can't handle different type in Config Maps, then what what would be ideal way to pass different application properties for Springboot application on kubernetese ?
I don't think the issue is related to the property value (3) being specified as a string ("3"). If you read the error message carefully you will see that the NumberFormatException is caused by an attempt to parse STARGATE_TOKEN_RETRY_LIMIT (literally) to a an int. Probably there is something wrong with the way the config map is passed to the application/container.
Related
I'm creating a JSON message from my ITSM solution, which uses Freemarker as a template tool.
The system returns a list of materials in the form of a string like this:
{ "[ZA00344] Toner Teste", "MATNR" : "[ZA00888] Caneta" }
Is there any built-in to extract the key between [] without using keep_after, keep_befor, or such functions? Cause these can eventually cause problems.
Thanks.
when creating TYPE in cassandra cli eg: cqlsh: create type cast (name text, role text) i am getting error
" line 1:16 mismatched input '(' expecting '.' (create type
cast[(]...) "
Actually i am using spring boot for creating TYPE in
cassandra-DB. I have tried manually in cassandra cli as well as in spring boot. Both are not working spring boot is throwing exception at the time running the application.
Please refer this link for more clarity ?
http://cassandra.apache.org/doc/latest/cql/functions.html
please help me on this.
Every object in Cassandra need to be defined in some keyspace. You either need to specify the full type name in form of keyspace.name, or execute use keyspace; before executing this command.
Looks like a bug in Cassandra (feel free to file a JIRA), if you really need to use that name, you can try to specify it as:
create type test."cast"(...
but in this case, the name of the type will be case sensitive, and you'll need always specify it in double quotes.
I am trying to condtionally create a component using #ConditionalOnExpression("not ${service.synchronous} && not ${service.disabled}").
I based this on Spring Boot SpEL ConditionalOnExpression check multiple properties, which provides a multi-property conditional as follows: #ConditionalOnExpression("${properties.first.property.enable:true} && ${properties.second.property.startServer:false}")
However, I keep getting:
Caused by: org.springframework.expression.spel.SpelParseException: EL1041E: After parsing a valid expression, there is still more data in the expression: 'lcurly({)'
Those properties are always set in my .properties file so I did not provide a default value with the colon notation. What am I doing wrong?
You will need to provide the default values for your properties like in the example you followed, so update the expression to be:
#ConditionalOnExpression("not ${service.synchronous:false} && not ${service.disabled:true}")
In most such cases the properties your app is reading are not what you expect them to be.
Set a breakpoint on all constructors of SpelParseException. In the debugger you will see the expression that is parsed, that will give show you exactly which properties you are really using.
Maybe you have to go search a little in the stack until you find the right location where you can see the expression.
My mistake was that I had not imported the test properties file in a Spring test.
After I added #TestPropertySource("classpath:/application.properties") to the test class, the properties from the properties file were used.
I am running a spring boot project where I need to parse an erro code dynamically, but I have realised that if the key is of integer type, it return null. Is there a way to parse Integer Keys in YAML file
Parsing This property doesnt work
errorcode:
00001: An error occurred whilst trying to process your request. We would like to apologise for the inconvenience.
Howver Parsing This property work
errorcode:
ONE: An error occurred whilst trying to process your request. We would like to apologise for the inconvenience.
I am trying to read this property using
import org.springframework.core.env.Environment;
#Autowired
private Environment environment;
error= environment.getProperty("errorcode.ONE") Works
error= environment.getProperty("errorcode.00001") --Doesn't works
So in nutshell, if an integer has been used as a key, YAML file is returning value as null. One workaround is to use the key this way as shown below, but any better ideas?
error
code-001:
It can be solved by specifying that number as string in yaml. like,
errorcode:
'00001': An error occurred whilst trying to process your request. We would like to apologise for the inconvenience.
This worked for me.
Read all string from the yaml and replace the integer value with non integer value. Descerialize the class with non integer value as variable.
I am writing a Grails (2.3.3 currently) application and have created a validateable command object similar to the following:
#Validateable
class MyCustomCommand {
String name
static constraints = {
name blank: false
}
}
In my i18n/messages.properties file I defined the following properties to override the default error messages.
MyCustomCommand.name.blank=Name must be provided.
MyCustomCommand.name.null=Name must be provided.
Which per the Grails documentation should be of the format [Class Name].[Property Name].[Constraint Code] as I have done. When I run my application if I leave the value blank I still get the default message for a null property.
I also tried following the example of the default messages and defining them a follows, but still get the default message.
MyCustomCommand.name.blank.message=Name must be provided.
MyCustomCommand.name.null.message=Name must be provided.
I am assuming that I am missing something simple here, but have yet to stumble upon what. Any suggestions on what I am doing incorrectly?
It is simple indeed. Message should look like:
myCustomCommand.name.blank=Name must be provided.
myCustomCommand.name.nullable=Name must be provided.
//className.propertyName.blank (camelCase with first letter of class name lower)
So, as I anticipated it was something simple. I was using the defaults as an example which used null where as what I really needed was nullable. Which does make sense as that matches the constraint name.
Therefore the correct version is:
myCustomCommand.name.blank=Name must be provided.
myCustomCommand.name.nullable=Name must be provided.