spring-4

multiple @ComponentScan in Spring 4?

跟風遠走 提交于 2019-12-04 04:29:01
I am using Spring 4.16 with Java Annotations, and i want to do something like: @Configuration @ComponentScan(basePackages = "com.example.business", includeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ServiceComponent.class)) @ComponentScan(basePackages = "com.example.business.framework") public class ServicesBaseConfiguration { } Obviusly, it doesn't compile. But i hope you get my point. I want to have multiple ComponentScans with differents packages and filters. I cannot unify both ComponentsScan because it wouldn't create any component from framework but those

how to pass application.properties in commandLine for a spring boot application?

感情迁移 提交于 2019-12-03 13:35:59
问题 I have a spring boot application and I want to pass application.properties file in commandLine when I start-up . i.e when I run mvn spring-boot:run --application.properties I will have a default application.properties in src/main/resources . but that is only for testing purposes. In the production run, I would like to pass the property file in commandLine. I am aware of passing single arguments such as mvn spring-boot:run --server.port=9001 . But I have many such properties and would prefer

Java 8 and Spring 4 : Use autowiring in interface

瘦欲@ 提交于 2019-12-03 07:09:58
问题 Java 8 added a new feature by which we can provide method implementation in interfaces. Is there any way in Spring 4 by which we can inject beans in the interface which can be used inside the method body? Below is the sample code public interface TestWiring{ @Autowired public Service service;// this is not possible as it would be static. //Is there any way I can inject any service bean which can be used inside testWiringMethod. default void testWiringMethod(){ // Call method of service

dynamic message-mapping for websockets in Spring 4

流过昼夜 提交于 2019-12-03 03:48:53
I want to develop a small chat with springs new websocket/stomp support. I guess i cannot use something like this: @MessageMapping("/connect/{roomId}") @SendTo("/topic/newMessage") public String connectToChatRoom(@PathVariable String roomId, Principal p) { return getTimestamp() + " " + p.getName() + " connected to the room."; } What are my options for dynamic mapping here? As a client i want to subscribe only to the room I'm in. Thanks in advance! Figured it out, you need to use @DestinationVariable instead of @PathVariable Yes the @MessageMapping annotation (javaadoc) and the reference docs

how to pass application.properties in commandLine for a spring boot application?

我是研究僧i 提交于 2019-12-03 03:13:20
I have a spring boot application and I want to pass application.properties file in commandLine when I start-up . i.e when I run mvn spring-boot:run --application.properties I will have a default application.properties in src/main/resources . but that is only for testing purposes. In the production run, I would like to pass the property file in commandLine. I am aware of passing single arguments such as mvn spring-boot:run --server.port=9001 . But I have many such properties and would prefer to pass a property file if that is possible. You can do that with spring.config.location property: mvn

Difference between the annotations @GetMapping and @RequestMapping(method = RequestMethod.GET)

随声附和 提交于 2019-12-03 01:23:58
问题 What's the difference between @GetMapping and @RequestMapping(method = RequestMethod.GET) ? I've seen in some Spring Reactive examples, that @GetMapping was used instead of @RequestMapping 回答1: @GetMapping is a composed annotation that acts as a shortcut for @RequestMapping(method = RequestMethod.GET) . @GetMapping is the newer annotaion. It supports consumes Consume options are : consumes = "text/plain" consumes = {"text/plain", "application/*"} For Further details see: GetMapping Annotation

Java 8 and Spring 4 : Use autowiring in interface

你。 提交于 2019-12-02 20:42:52
Java 8 added a new feature by which we can provide method implementation in interfaces. Is there any way in Spring 4 by which we can inject beans in the interface which can be used inside the method body? Below is the sample code public interface TestWiring{ @Autowired public Service service;// this is not possible as it would be static. //Is there any way I can inject any service bean which can be used inside testWiringMethod. default void testWiringMethod(){ // Call method of service service.testService(); } } This is a bit tricky but it works if you need the dependency inside the interface

MSSQL - JPA - Character encoding for Special characters - appending 'N' nativeQuery

柔情痞子 提交于 2019-12-02 18:19:02
问题 I'm using Spring 4.3.1 with JPA 2.0 and connected to MSSQL. I'm using JpaRepository's save method to insert and update data. One of the fields has nvarchar which can contain special characters like Latin, Chinese. Also, I have set below JPA properties in applicationContext-hibernate.xml. <prop key="hibernate.connection.CharSet">UTF-8</prop> <prop key="hibernate.connection.useUnicode">true</prop> <prop key="hibernate.connection.characterEncoding">UTF-8</prop> When I save the data, all the

Spring 4.0.x JSON/Ajax HTTP/1.1 406 Not Acceptable

旧时模样 提交于 2019-12-02 16:31:39
问题 I am working with Spring 4.0.5.RELEASE, Spring MVC through only Java Config I have in my pom.xml the following: <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>${jackson.version}</version> </dependency> Where <jackson.version>1.9.13</jackson.version> I am using the Spring default configuration about JSON. In some @Controller I have the following: @RequestMapping(value="/getjsonperson", method=RequestMethod.GET, produces=MediaType

Difference between the annotations @GetMapping and @RequestMapping(method = RequestMethod.GET)

核能气质少年 提交于 2019-12-02 14:46:19
What's the difference between @GetMapping and @RequestMapping(method = RequestMethod.GET) ? I've seen in some Spring Reactive examples, that @GetMapping was used instead of @RequestMapping @GetMapping is a composed annotation that acts as a shortcut for @RequestMapping(method = RequestMethod.GET) . @GetMapping is the newer annotaion. It supports consumes Consume options are : consumes = "text/plain" consumes = {"text/plain", "application/*"} For Further details see: GetMapping Annotation or read: request mapping variants RequestMapping supports consumes as well Deroude As you can see here :