How do I tell Spring Boot which main class to use for the executable jar?

Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.0.1.RELEASE:repackage failed: Unable to find a single main class from the following candidates My project has more than one class with a main method. How do I tell the Spring Boot Maven plugin which of the classes it should use as the main class? 10 Answers 10

What is the difference between ApplicationContext and WebApplicationContext in Spring MVC?

What is the difference between Application Context and Web Application Context? I am aware that WebApplicationContext is used for Spring MVC architecture oriented applications? I want to know what is the use of ApplicationContext in MVC applications? And what kind of beans are defined in ApplicationContext? 5 Answers 5

When use ResponseEntity and @RestController for Spring RESTful applications

I am working with Spring Framework 4.0.7, together with MVC and Rest I can work in peace with: @Controller ResponseEntity<T> For example: @Controller @RequestMapping(“/person”) @Profile(“responseentity”) public class PersonRestResponseEntityController { With the method (just to create) @RequestMapping(value=”https://stackoverflow.com/”, method=RequestMethod.POST) public ResponseEntity<Void> createPerson(@RequestBody Person person, UriComponentsBuilder ucb){ logger.info(“PersonRestResponseEntityController – createPerson”); if(person==null) logger.error(“person is null!!!”); else logger.info(“{}”, person.toString()); personMapRepository.savePerson(person); … Read more

What is the proper way to re-attach detached objects in Hibernate?

I have a situation in which I need to re-attach detached objects to a hibernate session, although an object of the same identity MAY already exist in the session, which will cause errors. Right now, I can do one of two things. getHibernateTemplate().update( obj ) This works if and only if an object doesn’t already … Read more

With Spring can I make an optional path variable?

With Spring 3.0, can I have an optional path variable? For example @RequestMapping(value = “/json/{type}”, method = RequestMethod.GET) public @ResponseBody TestBean testAjax( HttpServletRequest req, @PathVariable String type, @RequestParam(“track”) String track) { return new TestBean(); } Here I would like /json/abc or /json to call the same method. One obvious workaround declare type as a request … Read more

Spring MVC – How to get all request params in a map in Spring controller?

Sample URL: ../search/?attr1=value1&attr2=value2&attr4=value4 I do not know the names of attr1, att2, and attr4. I would like to be able to do something like that (or similar, don’t care, just as long as I have access to the Map of request param name -> value: @RequestMapping(value = “/search/{parameters}”, method = RequestMethod.GET) public void search(HttpServletRequest request, … Read more

How do I mock an autowired @Value field in Spring with Mockito?

I’m using Spring 3.1.4.RELEASE and Mockito 1.9.5. In my Spring class I have: @Value(“#{myProps[‘default.url’]}”) private String defaultUrl; @Value(“#{myProps[‘default.password’]}”) private String defaultrPassword; // … From my JUnit test, which I currently have set up like so: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({ “classpath:test-context.xml” }) public class MyTest { I would like to mock a value for my “defaultUrl” field. Note … Read more

intellij incorrectly saying no beans of type found for autowired repository

I have created a simple unit test but IntelliJ is incorrectly highlighting it red. marking it as an error No beans? As you can see below it passes the test? So it must be Autowired? 43 Answers 43 I had this same issue when creating a Spring Boot application using their @SpringBootApplication annotation. This annotation … Read more