Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Something error when use com.typesafe.config API convert conf file to scala bean class #792

Open
dragonpic1988 opened this issue Jul 12, 2023 · 0 comments

Comments

@dragonpic1988
Copy link

version 1.4.0
Did I make a mistake?
What is the correct way to do this?
scala code:
object AppMain {
def main(args: Array[String]): Unit = {
val conf = ConfigFactory.parseFile(new File("./center/app.conf"))
val app = ConfigBeanFactory.create(conf, classOf[App])
println("hello=" + app)
}
}

case class App(
config: Config
) {
def run(): Unit = {
println(config.run())
}
}

case class Config(
url: String,
safe: Boolean,
count: Int,
users: List[String]
) {
def run(): Unit = {
println("url=" + url)
println("safe=" + safe)
println("count=" + count)
println("users=" + users)
}
}
then, error:
Exception in thread "main" java.lang.reflect.InvocationTargetException
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 com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:64)
Caused by: com.typesafe.config.ConfigException$BadBean: com.saic.autobot.App needs a public no-args constructor to be used as a bean
at com.typesafe.config.impl.ConfigBeanImpl.createInternal(ConfigBeanImpl.java:129)
at com.typesafe.config.ConfigBeanFactory.create(ConfigBeanFactory.java:47)
at com.saic.autobot.AppMain$.main(AppMain.scala:13)
at com.saic.autobot.AppMain.main(AppMain.scala)
... 5 more
Caused by: java.lang.InstantiationException: com.saic.autobot.App
at java.lang.Class.newInstance(Class.java:427)
at com.typesafe.config.impl.ConfigBeanImpl.createInternal(ConfigBeanImpl.java:109)
... 8 more
Caused by: java.lang.NoSuchMethodException: com.saic.autobot.App.()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
... 9 more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant