Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8764603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:04:44+00:00 2026-06-13T16:04:44+00:00

I have the following spring pseudo-code wired scala class. @Service class Something { @Value(${some.property})

  • 0

I have the following spring pseudo-code wired scala class.

@Service
class Something {

@Value("${some.property}")
val someString : String

// do something with someString in the body
}

However this won’t work because the someString is part of the constructor body, and spring can’t wire in the values until after the constructor has executed.

How can I wire in @Value’s so that it works, and isn’t horrible (my current solution with a custom constructor containing all the values I need just doesn’t feel “scala” and looks horrible.

Edit: To clarify, my current solution is this:

@Service
class Something { 
  @Autowired 
  def this(@Value("${some.prop}") prop : String) { 
    this() 
    // do other construction stuff here
  }
}

I just think it looks ugly and feel there is a better way. I also don’t like having to create these secondary constructors when I’d rather enforce it on the primary constructor.

Edit 2: To further clarify, I was hoping there was a way to do something like this:

@Service
class Something(@Value("${some.property}") string : String) {
// use the value in your constructor here
}

Because this looks far more elegant. I just can’t get it to work 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:04:45+00:00Added an answer on June 13, 2026 at 4:04 pm

    Ok, after all the back and forth, I think I understand better what you want, so here’s my take on it:

    import scala.annotation.BeanProperty
    import scala.annotation.target.beanSetter
    class Something @Autowired() (@(Value @beanSetter)("{some.property}") @BeanProperty var prop: String)
    

    This is essentially Paolo Falabella’s solution, except that I try to avoid having Spring acces private fields. To this end I let scala autogenerate a public java-like setter using @BeanProperty and apply @Value on it.
    You can also improve the syntax somewhat by using a type alias:

    type Value = org.springframework.beans.factory.annotation.Value @beanSetter @beanGetter
    class Something @Autowired() ( @BeanProperty@Value("{some.property}") var prop: String)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say, I have the following bean in Spring context: <bean class=some.class.BlabBlahBlah> <property name=location value=classpath:somefile.xml/>
I have the following test case: @ContextConfiguration(/spring/test-context.xml) @TransactionConfiguration(transactionManager=txManager) @Transactional() public class MyEntityDaoTestCase extends AbstractJUnit4SpringContextTests
I have the following class (from a simple Spring tutorial) public class CarValidator implements
I have a Spring Batch process which has following kind of code. <step id=step1
i have following pseudo code : void siftup(int n) pre condition n>0 && heap(1,n-1)
So I have the following (pseudo code): string selectedvalud = C; List<SelectListItem> list= new
I have the following problem illustrated by the pseudo code below (might not make
I would like to define the following function in Objective-C. I have provided pseudo-code
To following is something like... pseudo code... To illustrate what I am looking for:
I am new to Spring Batch. I have following question. I am using Spring

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.