SpringBoot 2 and SDN 5 Unit Test hangs after start - spring-boot

I'm trying to migrate to SpringBoot 2 and SDN 5, working on just getting a unit test running. My test code:
#SpringBootTest
#ContextConfiguration(classes = com.playerscoach.auth.context.PersistenceContext.class)
#RunWith(SpringRunner.class)
public class AthleteRepositoryTest {
private static final Logger log = LoggerFactory.getLogger(AthleteRepositoryTest.class);
#Autowired
UserRepository userRepository;
#Autowired
private Session session;
#Autowired
private AthleteRepository athleteRepo;
private GraphDatabaseService graphDb;
private GraphAwareRuntime runtime;
#Before
public void setUp() {
GraphDatabaseService graphDb = new GraphDatabaseFactory()
.newEmbeddedDatabase(new File("var/graphDb"));
GraphAwareRuntime runtime = GraphAwareRuntimeFactory
.createRuntime(graphDb);
}
#After
public void tearDown() {
session.purgeDatabase();
}
/**
* Test of findByTitle method, of class MovieRepository.
*/
#Test
public void testFindByEmail() {
Athlete athlete = new Athlete.Builder()
.firstName("Alper")
.lastName("Akture")
.emailAddress("alper#test.com")
.password("password").build();
athleteRepo.save(athlete);
String email = "alper#test.com";
Collection<Athlete> result = athleteRepo.findByEmailAddress(email);
assertThat(result, notNullValue());
assertThat(result.iterator().next().getPassword(), is("password"));
}
#Test
public void testFindByLastName() {
String lastName = "Akture";
Collection<Athlete> result = athleteRepo.findByLastName(lastName);
assertThat(result, notNullValue());
assertThat(result.iterator().next().getPassword(), is("password"));
}
}
My repository:
public interface AthleteRepository extends Neo4jRepository<Athlete, Long> {
Collection<Athlete> findByEmailAddress(#Param("emailAddress") String emailAddress);
Collection<Athlete> findByLastName(#Param("lastName") String lastName);
#Query("MATCH (a:Athlete) WHERE a.emailAddress =~ ('(?i).*'+{emailAddress}+'.*') RETURN a")
Collection<Athlete> findByEmailContaining(#Param("emailAddress") String emailAddress);
}
My pom:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.M4</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<neo4j-ogm.version>3.0.0</neo4j-ogm.version>
<spring-data-releasetrain.version>Kay-RELEASE</spring-data-releasetrain.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- uncomment to use embedded -->
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-embedded-driver</artifactId>
<version>${neo4j-ogm.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>3.1.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.playerscoach.lib</groupId>
<artifactId>lib</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.graphaware.neo4j</groupId>
<artifactId>timetree</artifactId>
<version>3.2.1.51.27</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.graphaware.neo4j/graphaware-framework-embedded -->
<dependency>
<groupId>com.graphaware.neo4j</groupId>
<artifactId>graphaware-framework-embedded</artifactId>
<version>3.2.5.51</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.graphaware.neo4j</groupId>
<artifactId>tests</artifactId>
<version>3.2.5.51</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
<version>1.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.neo4j.test</groupId>
<artifactId>neo4j-harness</artifactId>
<version>3.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-kernel</artifactId>
<version>3.1.0</version>
<type>test-jar</type>
</dependency>
When I run the test, it hangs with the last line output in the log file:
07:53:03.526 [main] DEBUG org.springframework.boot.context.logging.ClasspathLoggingApplicationListener - Application failed to start with classpath:
with a dump of the entire classpath.
Any idea where I went wrong?

Related

Spring boot app getting "Error creating bean with name 'cassandraSession'"

I'm experiencing some troubles with Apache Cassandra and I think you could help me out!
So, this is my pom
<groupId>com.inboxapp</groupId>
<artifactId>inbox-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>inbox-app</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
</dependency>
<dependency>
<groupId>org.ocpsoft.prettytime</groupId>
<artifactId>prettytime</artifactId>
<version>5.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
These are my classes:
#Table(value = "folders_by_user")
public class Folder {
#PrimaryKeyColumn(name = "user_id", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
private String id;
#PrimaryKeyColumn(name = "label", ordinal = 1, type = PrimaryKeyType.CLUSTERED, ordering = Ordering.ASCENDING)
#CassandraType(type = CassandraType.Name.TEXT)
private String label;
// #PrimaryKeyColumn(name = "created_time_uuid", ordinal = 2, type = PrimaryKeyType.CLUSTERED, ordering = Ordering.ASCENDING)
// #CassandraType(type = CassandraType.Name.TEXT)
// private UUID createdTimeUuid;
#CassandraType(type = CassandraType.Name.TEXT)
private String color;
#Transient
private int unreadCount;
The config class:
#Configuration
#ConfigurationProperties(prefix = "datastax.astra")
public class DataStaxAstraProperties {
private File secureConnectBundle;
public File getSecureConnectBundle() {
return secureConnectBundle;
}
public void setSecureConnectBundle(File secureConnectBundle) {
this.secureConnectBundle = secureConnectBundle;
}
}
And the main:
#SpringBootApplication
#RestController
public class SpringGitHubLoginApplication {
public static void main(String[] args) {
SpringApplication.run(SpringGitHubLoginApplication.class, args);
}
#Bean
public CqlSessionBuilderCustomizer sessionBuilderCustomizer(DataStaxAstraProperties astraProperties) {
Path bundle = astraProperties.getSecureConnectBundle().toPath();
return builder -> builder.withCloudSecureConnectBundle(bundle);
}
}
There's soomething missing that I'm not seeing or what? As far as I can see there's no annotation missing. I've to say that I've done also the repository (not included here).
Thanks in adnvace!

Error while creating dynamic cloud config using actuator

The controller is InfyGo_Booking to which #RefreshScope is added and also added required dependencies in pom.xml. I have also exposed the endpoints in bootstrap.properties. But still https://localhost:9000/actuator/refresh is giving me 404 error. Can you help me pointing out if I am missing something?
Controller:
#RestController
#RefreshScope
#RequestMapping("/book")
public class BookingController {
protected Logger logger = Logger.getLogger(BookingController.class.getName());
#Autowired
private TicketService ticketService;
#Autowired
private PassengerService passengerService;
private Ticket ticket;
private int noOfSeats;
ClientHttpRequestFactory requestFactory = new
HttpComponentsClientHttpRequestFactory(HttpClients.createDefault());
RestTemplate restTemplate = new RestTemplate(requestFactory);
//
public BookingController() {
ticket = new Ticket();
}
#PostMapping(value = "/{flightId}/{username}", produces = "application/json", consumes = "application/json")
public ResponseEntity<BookingDetails> bookFlight(#PathVariable("flightId") String flightId,
#Valid #RequestBody PassengerDetails passengerDetails, #PathVariable("username") String username,Errors errors) throws InfyGoServiceException, ARSServiceException {
if (errors.hasErrors()) {
return new ResponseEntity(new ClientErrorInformation(HttpStatus.BAD_REQUEST.value(),errors.getFieldError("passengerList").getDefaultMessage()), HttpStatus.BAD_REQUEST);
}
if(passengerDetails.getPassengerList().isEmpty())
throw new InfyGoServiceException(ExceptionConstants.PASSENGER_LIST_EMPTY.toString());
List<Passenger> passengerList = new ArrayList<Passenger>();
for (Passenger passengers : passengerDetails.getPassengerList()) {
passengerList.add(passengers);
}
System.out.println(passengerList.toString());
logger.log(Level.INFO, "Book Flight method ");
logger.log(Level.INFO, passengerDetails.toString());
int pnr = (int) (Math.random() * 1858955);
ticket.setPnr(pnr);
// Date date = new Date();
// Calendar calendar = Calendar.getInstance();
// calendar.setTime(date);
Flight flightDto= restTemplate.getForObject("http://localhost:9004/flights/"+flightId, Flight.class);
double fare= flightDto.getFare();
System.out.println("Fare per person:****** " + fare);
System.out.println("List size:****** " + passengerDetails.getPassengerList().size());
double totalFare = fare * (passengerDetails.getPassengerList().size());
BookingDetails bookingDetails = new BookingDetails();
bookingDetails.setPassengerList(passengerDetails.getPassengerList());
bookingDetails.setPnr(pnr);
bookingDetails.setTotalFare(totalFare);
ticket.setBookingDate(new Date());
System.out.println(ticket.getBookingDate());
ticket.setDepartureDate(flightDto.getFlightAvailableDate());
ticket.setDepartureTime(flightDto.getDepartureTime());
ticket.setFlightId(flightDto.getFlightId());
ticket.setUserId(username);
ticket.setTotalFare(totalFare);
noOfSeats = passengerDetails.getPassengerList().size();
ticket.setNoOfSeats(noOfSeats);
ticketService.createTicket(ticket);
addPassengers(bookingDetails.getPassengerList());
restTemplate.postForEntity("http://localhost:9004/flights/"+flightId+"/"+noOfSeats,null,null);
return new ResponseEntity<BookingDetails>(bookingDetails, HttpStatus.OK);
}
private void addPassengers(List<Passenger> passengers) {
for (Passenger passenger : passengers) {
passenger.setTicket(ticket);
}
passengerService.createPassenger(passengers);
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR5</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.12</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
bootstrap.properties:
spring.cloud.config.uri=http://localhost:1111
management.endpoints.web.exposure.include=*
It looks like you are trying to call the actuator as a URL from browser which by default uses GET method . Please try the same URL and hit a post request using any app , you must see a success response .

Getting 'Whitelabel Error Page' error in Spring Boot 2

I am getting the following error when I am calling my dashboard home page.http://localhost:8082/web/fix/dashboard
What I understood from it is that the JSP file /WEB-INF/jsp/dashboard.jsp is missing somehow or maybe spring won't able to find it or maybe I did something wrong.
To make sure I tried decompiling the jar but JSP file was missing. don't know where it is?
I have placed JSP file in src/main/webapp/WEB-INF/jsp/dashboard.jsp.
However, this problem only occurs while running an application using the jar file. It works fine in eclipse.
java -jar application.jar
It is a maven project.
Application.properties
spring.profiles.active=dev
spring.main.allow-bean-definition-overriding=true
server.address=127.0.0.1
server.port=8082
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.fidel.fixadaptor</groupId>
<artifactId>fix-adaptor</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>fix-adaptor</name>
<description>Demo project for Spring Boot</description>
<properties>
<maven.test.skip>true</maven.test.skip>
<java.version>1.8</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.9.RELEASE</version>
<relativePath />
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<!-- <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-core</artifactId>
<version>2.3.0</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId> <version>2.3.0</version> </dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.quickfixj</groupId>
<artifactId>quickfixj-core</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.quickfixj</groupId>
<artifactId>quickfixj-messages-fix50sp2</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.mindrot</groupId>
<artifactId>jbcrypt</artifactId>
<version>0.3m</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency> -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
Controller
#Controller
#RequestMapping(path = "/web/")
public class WebController {
#Autowired
ConfigurationService configurationService;
#Autowired
private Destination destination;
#Autowired
private Gson gson;
#GetMapping(path = "fix/dashboard")
public String dashBoard(Model model) {
// view to render
return "dashboard";
}
}
Application Class
#SpringBootApplication
#ComponentScan("com.covacap.bloomberg")
public class CovacapTerminalRunner extends SpringBootServletInitializer
implements CommandLineRunner {
/** The adaptor runner. */
#Autowired
CovacapRunner adaptorRunner;
/** The Constant LOGGER. */
private static final Logger LOGGER =
LoggerFactory.getLogger(CovacapTerminalRunner.class);
/**
* The main method.
*
* #param args the arguments
*/
public static void main(String[] args) {
ConfigurableApplicationContext context =
SpringApplication.run(CovacapTerminalRunner.class, args);
try {
String[] list = context.getBeanDefinitionNames();
for (String string : list) {
LOGGER.info(string);
}
context.getBean(AdaptorDestination.class).autoStart();
} catch (BeansException | ConfigException e) {
e.printStackTrace();
}
}
/**
* {#inheritDoc}
*
* #param args
* #throws Exception
*/
#Override
public void run(String... args) throws Exception {
// adaptorRunner.run(args);
}
}
Please help on this
Since the jsp files are missing and as you mentioned after decompiling the jar file the jsp files are not there means that maven doesn't copy them when you bundle the jar file.
Try telling maven to manually copy the webapp folder as a resource similar to the
below snippet
<build>
<resources>
...
<resource>
<directory>src/main/webapp</directory>
</resource>
...
</resources>
...
</build>

Error creating bean with the name localContainerEntityManagerFactorryBean defined in the class path resource hibernateconfig.class

I'm getting the Error creating bean with the name localContainerEntityManagerFactorryBean defined in the class path resource hibernateconfig.class. nested exception is javax.persistence.persistenceException:unable to build hibernate session factory: A foreign key referring organizer from events has the wrong no of column, should be 2.
My pom file is
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.EventToday</groupId>
<artifactId>EventToday</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>EventToday</name>
<description>projects for events</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<springframework.version>4.0.6.RELEASE</springframework.version>
<hibernate.version>4.3.6.Final</hibernate.version>
<mysql.version>5.1.31</mysql.version>
<joda-time.version>2.3</joda-time.version>
<testng.version>6.9.4</testng.version>
<mockito.version>1.10.19</mockito.version>
<h2.version>1.4.187</h2.version>
<dbunit.version>2.2</dbunit.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>ejb3-persistence</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<!-- jsr303 validation -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.0.2.GA</version>
</dependency>
<!-- MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<!-- Joda-Time -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<!-- To map JodaTime with database type -->
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>3.0.0.CR1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<warName>EventToday</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
<compilerArgs>
<arg>-Aopenjpa.metamodel=true</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
and hibernate configuration
#Configuration
#EnableTransactionManagement
#EnableJpaRepositories("com.EventToday.event.repository")
#ComponentScan({ "com.EventToday.event" })
#PropertySource(value = { "classpath:application.properties" })
public class hibernateconfig {
#Autowired
private Environment environment;
#Bean
public LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean() {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setDatabase(Database.MYSQL);
//vendorAdapter.setGenerateDdl(generateDDL);
vendorAdapter.setShowSql(true);
LocalContainerEntityManagerFactoryBean beanFactory = new LocalContainerEntityManagerFactoryBean();
beanFactory.setJpaVendorAdapter(vendorAdapter);
beanFactory.setPackagesToScan("com.EventToday.event.model");
beanFactory.setDataSource(dataSource());
//beanFactory.afterPropertiesSet();
beanFactory.setJpaProperties(hibernateProperties());
return beanFactory;
}
#Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(environment.getRequiredProperty("spring.datasource.driverClassName"));
dataSource.setUrl(environment.getRequiredProperty("spring.datasource.url"));
dataSource.setSchema(environment.getRequiredProperty("spring.datasource.schema"));
dataSource.setUsername(environment.getRequiredProperty("spring.datasource.username"));
dataSource.setPassword(environment.getRequiredProperty("spring.datasource.password"));
return dataSource;
}
private Properties hibernateProperties() {
Properties properties = new Properties();
properties.put("spring.jpa.properties.hibernate.dialect", environment.getRequiredProperty("spring.jpa.properties.hibernate.dialect"));
properties.put("spring.jpa.show_sql", environment.getRequiredProperty("spring.jpa.show-sql"));
properties.put("spring.jpa.properties.hibernate.format_sql", environment.getRequiredProperty("spring.jpa.properties.hibernate.format_sql"));
return properties;
}
#Bean
public EntityManagerFactory entityManagerFactory(){
return localContainerEntityManagerFactoryBean().getObject();
}
#Bean
public EntityManager entityManager(){
return entityManagerFactory().createEntityManager();
}
#Bean
PlatformTransactionManager transactionManager(){
JpaTransactionManager manager = new JpaTransactionManager();
manager.setEntityManagerFactory(entityManagerFactory());
return manager;
}
#Bean
public HibernateExceptionTranslator hibernateExceptionTranslator(){
return new HibernateExceptionTranslator();
}
}
organizer
#Entity
#Table(name="organizer")
public class Organizer extends BaseEntity{
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private int roid;
#Column(name="orgNname", nullable=false)
private String organizerName;
#Column(name = "org_contact", nullable = false)
private String orgTelephone;
#Column(name = "org_altcontact", nullable = false)
private String orgContact;
#Column(name = "org_mail_address", nullable = false)
private String mailAddress;
#Column(name = "org_address", nullable = false)
private String orgAddress;
#OneToMany(mappedBy = "organizer")
private Set<events> evts;
public Set<events> getEvts() {
return evts;
}
public void setEvts(Set<events> evts) {
this.evts = evts;
}
public Organizer() {
}
//getters and setters
}
#events
#Entity
#Table(name="event")
public class events extends BaseEntity{
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
#ManyToOne
#JoinColumn(name = "roid")
private Organizer organizer;
public events() {
}
#Column(name = "event_name", nullable = false)
private String eventname;
#Column(name = "event_date", nullable = false)
#DateTimeFormat(pattern="dd/MM/yyyy")
#Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
private LocalDate date;
#NotNull
#Digits(integer=8, fraction=2)
#Column(name = "ticket_price", nullable = false)
private BigDecimal price;
#Column(name="event_location", nullable=false)
private String location;
#Column(name="happening_city", nullable=false)
private String Address;
#Column(name="contact_no", nullable=false)
private String contact_no;
#Column(name="alt_contact_no", nullable=false)
private String alternate_contact;
#Column(name="mail_address")
private String mail_address;
//getters and setters
}

Why Spring Boot 1.4.0.RELEASE doesn't support LocalDateTime of Java 8 automatically

I have a Spring Boot application and I use LocalDateTime but I need to explicit configure the converter of Jsr310 for my LocalDateTime property:
Application.class (the main class)
#SpringBootApplication
#EntityScan(basePackageClasses = { Application.class, Jsr310JpaConverters.class })
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Entity example:
#Entity
public class News {
#Id
private Long id;
#JsonFormat(pattern = "dd/MM/yyyy HH:mm:ss")
private LocalDateTime datetime;
...
Repository:
public interface NewsRepository extends JpaRepository<News, Long> {
#Modifying
#Transactional
#Query("DELETE FROM News n WHERE n.datetime < :datetime")
void deleteByDatetimeBefore(#Param("datetime") LocalDateTime datetime);
}
Pom file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>test</name>
<description>Test</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Not should be automatic? Why I need configure this?
#EntityScan(basePackageClasses = { Application.class, Jsr310JpaConverters.class })
And why I need to write the delete Query:
#Query("DELETE FROM News n WHERE n.datetime < :datetime")
void deleteByDatetimeBefore(#Param("datetime") LocalDateTime datetime);
This should not be automatic like:
#Transactional
Long deleteByDatetimeBefore(LocalDateTime datetime);

Resources