Traits are not allowed to have constructor parameters.
Instead, you could define a sub-trait that specified myJMXBeanServer
for you (I'm not quite sure why you think initialization in one single place is bad --- it's either that or initialization in several places, which is what you have now):
class MyParent
trait MyMetricsHelper {
val server: AnyRef // Replace by actual type, this means
// that we expect any impl. to initialize this field somehow
}
trait MyJMXMetricsHelper extends MyMetricsHelper {
val server = "myJMXMBeanServer"
}
class MyClass1 extends MyParent with MyJMXMetricsHelper
class MyClass2 extends MyParent with MyJMXMetricsHelper
class MyClass3 extends MyParent with MyJMXMetricsHelper