spring - Inconsistent run of springboot application when run in Eclipse

I have observed an inconsistent way properties are being read in Eclipse. I have a very simple Springboot web project with typical property files. Here is my project layout: Notice the two property files: testapplication.properties and application.properties. They are identical at this point, the intention is to use them for test and non test environments. When I try to run this application in Eclipse, I am getting an error about missing expected property values, for example: Could not resolve placeholder 'min.thread.count' in value "${min....Read more

How to reject access in Spring after successful authentication

I'm implementing some REST services in Spring and need to reject, in some cases, a successful login of a user.I have implemented my UserDetailsService and programmed the loadUserByUsername(String username) method, but, when a user gets correctly authenticated, I need to do another validation and, if it fails, reject the access.To do so I have implemented a listener to detect correct authentications:@Componentpublic class LoginSuccessListener implements ApplicationListener{ @Autowired LicenseControlService licenseControlService;@Overridepu...Read more

Should marshal/demarshaling be in service (transactional) methods or controller in spring boot project?

I am working on spring boot application with CRUD api with input and output as json object. Is it okay to include json->POJO and POJO->json logic in service method? (service method is marked with transactional annotation)//Controller public Map<String, String> getPersonNames(){ return personSvc.getNames();}//Service method@Transactional(readonly = true)public Map<String, String> getNames(){ return populateNames(repo.findAll());}private Map<String, String> populateNames(final List<Person> personList) { return Im...Read more

Spring Controller Mapping Issues - Double Wildcard

I would like to map the following URL:/resource/{path/to/git/repo.git}/{branch}/{path/within/repository}To a Spring Framework controller. However I am having some issues. I have tried the following pattern with no success:/resource/**.git/{branch}/**matches resource/anything.git/branch/path/etc (no slashes in the path to git repo)does not match resource/path/anything.git/branch/path/etc as I would expectI have also tried /resource/**/.git/{branch}/** in testing which behaves as expected, allowing any number of slashes in both Ant Pattern wildca...Read more

rest - Ways to integrate spring MVC with Restful web services

I am trying to understand Spring MVC Restful architecture. Want to know how many ways are there to integrate spring MVC with Restful web services. I can see one of it is using Rest Template. Is it the only way to use rest web services in Spring MVC.Can we develop web application using spring MVC alone without consuming any web services.Please correct me if am wrong .Thanks for the help....Read more

why properties from appliction.properties not available in Junit test in spring boot application?

I have a spring boot application. I am writing Junit tests.I am trying to inject values from application.properties (defined in src/main/resources/application.properties) and a Status bean configured in AppConfig (src/main/java/hello/AppConfig.java). I see that the bean is autowired (through debugger it is not null) but the values are not set.Here is application.propertiessrc/main/resources/application.propertiesapp.name=rest-serviceapp.version=1.0.0-SNAPSHOTsrc/main/java/hello/AppConfig.java@Configurationpublic class AppConfig { @Value("${a...Read more

spring - How to sum the array size across the entire collection?

i hava a mongodb json data.{ "_id" : ObjectId("1111111111111111"), "teamId" : "111", "scoreId" : "50dcefb52d764ca3913985a80a4162ef", "utterances" : [ { "text" : "test1", "parsedText" : "test1" }, { "text" : "test2", "parsedText" : "test2" } ]},{ "_id" : ObjectId("22222222222222"), "teamId" : "111", "scoreId" : "60dcefb52d764ca3913985a80a4162ef", "utterances" : [ { "text" : "do it1", "parsedText" : "do it1" },...Read more

Spring application - jdbc commit

I have a Spring application migrating from WebLogic to Tomcat (ucp connection pool). Started noticing a weird behavior where we see SQLs getting executed but not committed but not consistent in different environments. Some of the calls are not annotated with txn but wondering how is jdbctemplate.update committing the transactions if its not annotated with transaction?...Read more

spring - How to handle Facade in feature by package structure

How can I structure my project if I have a facade?The controller will call the facade to call the class in another package and the self package?Like:feature/├── order/│ ├── OrderController <== here calls Facade│ ├── OrderService└── facade/│ ├── CheckoutFacade <== here calls orderService(go to facade and back to self package) and personService └── person/ └── PersonServiceShould I create a controller package separately of feature?...Read more

Spring Batch Parallel Processing - File Splitting at runtime

I have a Simple Spring Batch which reads, say, 1 million records, from a file and prints it on the console.Now, I want to deploy this batch on N servers, say N=5.How can I make sure that are same records are NOT being read by all the server instances ?As in - how I can split the records in file appropriately ( 1 million / 5) to achieve optimized results ?Please help with code examples.Thanks....Read more

spring boot - web mvc test does not find controller mapping

In this spring-boot project the following WebMvcTest fails because the GET /items mapping from the ItemController is not found @RunWith(SpringRunner.class)@WebMvcTest(ItemController.class)@AutoConfigureMockMvcpublic class Test_ItemController { @Autowired private MockMvc mvc; @MockBean private ItemDao dao; @MockBean private CartDao cartDao; @Test public void test() throws Exception { // setting up mock response Cart cart = new Cart(); cart.setId(1); Item item = new Item(); item.setCart(c...Read more

spring - Is a mock MongoRepository saving objects?

I am using SpringBoot 1.5.9 and try to do Integration testing. Weirdly a MongoRepository.save() method updates the object when called on mock MongoRepository. I have a Counter Classpublic class Counter { public String id; public int seq; public void increaseSeq() { this.seq += 1; }}And his repositorypublic interface CounterRepository extends MongoRepository<Counter, String>{ Counter findById(String id); List<Counter> findAll();}And his service@Servicepublic class CounterService { @Autowired private Co...Read more