Paul N
06/17/2020, 11:18 AM@Retryable(backoff = @Backoff(delay = 2222)) // won't compile
fun doIt() {
}
Java:
public class Delme {
@Retryable(backoff = @Backoff(delay = 2222))
void doIt() {
}
}
Shawn A
06/22/2020, 10:55 PM@GetMapping("/api/users")
fun getAll(user: User) = Mono.just(user)
-- snip --
data class User(
val firstName: String,
val address: Address
)
data class Address(
val street: String
)
Curl:
curl '<http://localhost:8080/api/users?firstName=shawn&address.street=foo>'
500 error:
org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.expediagroup.application.User]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Parameter specified as non-null is null: method com.expediagroup.application.User.<init>, parameter address
I am pretty sure this works with the servlet API.ashmelev
06/23/2020, 12:40 AMfun getAll(@RequestBody @Validated user: User).....
Iain Cambridge
06/23/2020, 4:00 PMdata class Credential(
@field:JsonProperty("country_code")
@field:Pattern(regexp = "^[A-Z]{2}$", message = "country_code must be a string of 2 capital letters i.e. DE")
val countryCode: String? = null,
)
With
fun registerCredentials(@Validated @RequestBody credential: Credential):Credential{
//...
}
I've tried @Valid
and that doesn't work either. I don't get any error, I just ged a object with null values.Marian Schubert
06/27/2020, 7:38 PMStian N
06/29/2020, 10:57 AMobject?
signature, and you can work around this with !!
. Is this the prefered method?Ashish Kumar Joy
06/29/2020, 5:40 PMSandy
06/30/2020, 12:09 AMDennis Schröder
07/02/2020, 11:12 AM@Value("\${some.value:default}") someValue: String
bjonnh
07/08/2020, 9:02 PMDariusz Kuc
07/10/2020, 9:47 PMFactoryBean
I’m hitting some weird (at least to me) behavior - when I create the underlying object I need to configure it with some beans retrieved from application context (factory is application context aware). Weird part is the different behavior between retrieving bean by name (works - loads necessary autoconfigs) and the type (fails -> dependent config is not loaded).
// works - dependent auto config is loaded
val targetBean = applicationContext.getBean("targetBeanName")
// blows up with no bean
val targetBean = applicationContext.getBean(TargetBean::class.java)
Any ideas?iari
07/13/2020, 10:47 AMval adminRole = roles.findByName("admin")!!
val adminUser = BackendUser("admin", adminRole
// some more data here
)
users.save(adminUser)
and get
org.hibernate.PersistentObjectException: detached entity passed to persist: my.package.name.user.UserRole
More details are in this SO post:
https://stackoverflow.com/questions/62874155/spring-data-hibernate-detached-entity-passed-to-persist
Any help would be appreciated.Jeremy
07/17/2020, 1:57 PMorg.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'text/html;charset=utf-8' not supported for bodyType
.
Here's the service:
val client = WebClient.builder()
.baseUrl(apiUrl)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.ALL_VALUE)
.defaultHeader("X-API-TOKEN", apiToken)
.build()
return client.get()
.uri("/$directoryId/mailinglists/$mailingListId")
.accept(MediaType.APPLICATION_JSON, MediaType.TEXT_HTML)
.acceptCharset(Charset.forName("UTF-8"))
.retrieve()
.bodyToMono(GetMailingListResponse::class.java)
Here's the controller:
@GetMapping("/directories/{directoryId}/mailinglists/{mailingListId}")
fun handle(@PathVariable directoryId: String, @PathVariable mailingListId: String): Mono<ResponseEntity<GetMailingListResponse>> {
val resp = service.createMailingList(directoryId, mailingListId)
return resp.map {
body -> ResponseEntity.ok(body)
}
}
Any help would be appreciated.hooliooo
07/21/2020, 6:21 AMHanwool Seok
07/28/2020, 10:35 AMReddyTintaya
07/30/2020, 5:09 PMJose Antonio Jimenez
08/04/2020, 10:51 AMJP
08/04/2020, 1:35 PM@Autowired
with Kotlin,
I’m confused whether this
@Autowired
private lateinit var userService: UserService
is a field injection or a setter injection.
In the documentation, the Kotlin equivalent of both field and setter injection of Java were all in this fashion.
I read that field injection should be avoided, and I’ll try to stick with constructor injection if possible, but I’m just trying them out to learn.
If there is actually like a more stricter equivalents, I’d like to know how to write them in Kotlin.
Can anyone shed some light on this to me?nathan
08/13/2020, 9:10 PM@Entity
@Table(name="storypost")
class StoryPost(
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "storypost_id")
var id: Long,
var body: String,
var video_link: String,
var image_link: String,
var likes: Int,
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "userprofile_id")
@JsonBackReference
var userProfile: UserProfile?=null
)
Controller
@RestController
class StoryPostController ( val repo : StoryPostRepositories){
@GetMapping("/storypost")
fun getAllStoryPosts() = repo.findAll().toList()
@PostMapping("/storypost")
fun addStoryPost(@RequestBody userPost : StoryPost) : ResponseEntity<StoryPost>{
repo.save(userPost)
return ResponseEntity<StoryPost>(userPost, HttpStatus.CREATED)
}
}
how would I include the user id when making a storypost post request? should i just put another var user_id: Long
and then have a val repo2 : UserRepo
to find by id?kenkyee
08/15/2020, 11:12 AMmp
08/18/2020, 10:40 AMManuel Lorenzo
08/18/2020, 1:50 PMManuel Lorenzo
08/18/2020, 1:51 PMDariusz Kuc
08/19/2020, 6:01 PMBeanDefinitionBuilder.genericBeanDefinition(MyFactoryBean::class.java)
• MyFactoryBean
is application context aware and it attempts to retrieve FallbackBean
from context (e.g. using applicationContext.getBean(FallbackBean::class.java)
• within a @SpringBootTest
I’m explicitly creating SomeBean
in a configuration class
So my problem is that conditional logic (i.e. @ConditionalOnBean
) is evaluated BEFORE attempting to create the SomeBean
in test configuration…. Sample code in the thread. Any ideas what I might be missing?xii
08/23/2020, 11:10 PMDosExe
08/25/2020, 3:57 PMclass BeansInitializer : ApplicationContextInitializer<GenericApplicationContext> {
override fun initialize(context: GenericApplicationContext) {
beans().initialize(context)
}
}
2. Set context.initializer.classes=com.package.BeansInitializer in application.properties
It helped a little bit, now some of the beans are created, but all beans with @ConfigurationsProperties are still not created.Dariusz Kuc
08/27/2020, 2:46 PMAyodele
08/29/2020, 9:13 AM@Mapper
@Component
interface UserMapper {
fun toUserDTO(user: User): UserDTO
fun toListOfUserDTO(users: List<User>) : List<UserDTO>
fun toUser(userDTO: UserDTO) : User
fun toListOfUser(userDTOs: List<UserDTO>) : List<User>
}
and i'm using it in my contoller
@Autowired
lateinit var userMapper: UserMapper
It gives this error, please help
***************************
APPLICATION FAILED TO START
***************************
Description:
Field userMapper in com.scienta.backend_rated_ng.controller.AuthController required a bean of type 'com.scienta.backend_rated_ng.mapper.UserMapper' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.scienta.backend_rated_ng.mapper.UserMapper' in your configuration.
I have all my dependencies rightPhilipp Mayer
08/29/2020, 5:38 PM@GetMapping("/")
fun index(model: Model): String {
model.addAttribute(....)
return "index"
}
and I would like to convert it to the new dsl.
router {
accept(MediaType.TEXT_HTML).nest {
GET("/") { index(/*model param missing*/) }
}
Could one give me a hint how to handle the parameter model: Model
accordingly?
Thanks a lot!nathan
09/01/2020, 2:25 AMnathan
09/01/2020, 2:25 AMAlexJuca
09/05/2020, 9:30 AM