SpringBoot property value inside annotation - spring

I have this annotation
#Listener(topics = "test")
that I want to relace with
#Listener(topics = "#Value(\"${topics}\")")
but I have this error
Could not resolve placeholder 'topics' in value "#Value("${topics}")"

Try:
#Listener(topics = "${topics}")
and make sure the property actually exists.
(Not a 100% sure that it works, but somewhat confident ;) )

Related

Is this possible to fine tune T5 by changing its configuration using T5Config class object?

Trained the "T5-base" as given in the video tutorial of Venelin Valkov. It is working well. Then I tried to change some configuration like the number of layers (num_layers) and drop out in layers (dropout_rate) using
config = T5Config(num_layers=8, dropout_rate=0.2)
and then including the config object in
self.model = T5ForConditionalGeneration.from_pretrained("t5-base", config=config, return_dict = True)
as given here, but it didn't work. It returns an error
TypeError: init() got an unexpected keyword argument 'return_dict'
Please help.

Gradle - Cannot set property on null object

I have a .gradle in which I want to set some project properties if a condition is true.
def isRelease = project.getProperty('isRelease')
if (isRelease) {
println 'Detected a release'
project.properties.'releaseCenter'.'uploadURL' = project.properties.'uatUploadURL'
}
The output is:
A problem occurred evaluating root project 'tasks'.
> Cannot set property 'uploadURL' on null object
I think it has to do with the '' around the object name but I couldn't get it to work.
Any help is much appreciated.
You call project.properties: https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html#getProperties--
which returns a Map. You then call properties.'releaseCenter' which is equivalent to doing properties.get("releaseCenter") which returns null. You try to get a property on a null object which is exactly the error you are seeing.
Possible solutions:
Fix your Gradle configuration (some plugin may be adding this property)
Define the property yourself.

How to use polymorphism to remove a switch statement which compares strings?

I am new to Ruby, so let me describe the context of my problem first:
I have a json as input which has the following key / value pair:
{
"service": "update"
}
The value has many different values for example: insert,delete etc.
Next there is a method x which handles the different requests:
def x(input)
case input[:service]
services = GenericService.new
when "update"
result = services.service(UpdateService.new,input)
when "insert"
result = services.service(InsertService.new,input)
when "delete"
result = services.service(DeleteService.new,input)
....
....
else
raise "Unknown service"
end
puts JSON.pretty_generate(result)
end
What is bothering me is that I still need to use a switch statement to check the String values (reminds me of 'instance of' ugh..). Is there a cleaner way (not need to use a switch)?
Finally I tried to search for an answer to my question and did not succeed, if however I missed it feel free to comment the related question.
Update: I was thinking to maybe cast the string to the related class name as follows: How do I create a class instance from a string name in ruby? and then call result = services.services(x.constantize.new,input) , then the class names ofcourse needs to match the input of the json.
You can try something like:
def x(input)
service_class_name = "#{input[:service].capitalize}Service"
service_class = Kernel.const_get(service_class_name)
service_class.new(input).process
end
In addition you might want to check if this is a valid Service class name at all.
I don't understand why you want to pass the service to GenericService this seems strange. let the service do it's job.
If you're trying to instatiate a class by it's name you're actually speaking about Reflection rather than Polymorphism.
In Ruby you can achieve this in this way:
byName = Object.const_get('YourClassName')
or if you are in a Rails app
byName= 'YourClassName'.constantize
Hope this helps
Just first thoughts, but you can do:
eval(services.service("#{input[:service].capitalize}Service.new, #{input})") if valid_service? input[:service]
def valid_service?
w%(delete update insert).include? input[:service]
end
As folks will no doubt shout, eval needs to be used with alot of care

How to create XML object from string using xml-mapping in Ruby

I'm using xml-mapping in Ruby (on Sinatra) for some XML stuff. Generally I follow this tutorial: http://xml-mapping.rubyforge.org/. I can create objects and write them to XML strings using
login.save_to_xml.to_s
But when I try
login = Login.load_from_xml(xml_string)
I get the following error:
XML::MappingError - no value, and no default value: Attribute username not set (XXPathError: path not found: username):
Here is the XML string I receive:
<login><username>ali</username><password>baba</password></login>
This is what the class looks like:
class Login
include XML::Mapping
text_node :username, "username"
text_node :password, "password"
end
So the class name is the same, the nodes are named the same. I actually get the exact same string when I create an instance of my object and fill it with ali/baba:
test = Login.new
test.username = "ali"
test.password = "baba"
p test.save_to_xml.to_s
<login><username>ali</username><password>baba</password></login>
What am I missing?
Thanks,
MrB
EDIT:
When I do
test = login.save_to_xml
And then
login = Login.load_from_xml(test)
it works. So the problem seems to be that I'm passing a string, while the method is expecting.. well, something else. There is definitely a load_from_xml(string) method in the rubydocs, so not sure what to pass here. I guess I need some kind of reverse to_s?
It looks like you save_to_xml creates a REXML::Element. Since that works, you may want to try:
Login.load_from_xml(REXML::Document.new(xml_string).root)
See the section on "choice_node" for a more detailed example http://xml-mapping.rubyforge.org/

Object variable not set error in vb6

Private m_IncidentDateRange As New MCWebServiceCOMWrapper.DateRange
Public Property Get IncidentDateRange() As MCWebServiceCOMWrapper.DateRange
IncidentDateRange = m_IncidentDateRange
End Property
Public Property Let IncidentDateRange(ByRef vNewValue As MCWebServiceCOMWrapper.DateRange)
Set m_IncidentDateRange = vNewValue
End Property
Error comes up in Get method please help
I would check the documentation for the MCWebServiceCOMWrapper.DateRange object and see if you are required to initialized it with values before you can use it. (maybe set a beginning and end date).
Don't you need to use "Set" there?

Resources