Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ There are 2 modules:
Where api is dependent on some packages from service.
The main idea was to create valid module-info.java classes to define valid exports, but, which is more important even, to open valid packages to Spring to be used via reflection.

The application cannot be started via Intellij IDEA.
In order to run via Intellij IDEA:
Set VM options: `--add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED`

In order to run:
* mvn clean install
* java -jar api/target/api-1.0-SNAPSHOT-exec.jar
In order to run through command line:
```bash
mvn clean install

java --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED -jar api/target/api-1.0-SNAPSHOT-exec.jar
```
9 changes: 9 additions & 0 deletions service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,14 @@
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;

@Configuration
@ComponentScan("com.lohika.morning.java9modules.service.*")
//@EnableMongoRepositories("com.lohika.morning.java9modules.service.repository")
@EnableMongoRepositories(basePackages = "com.lohika.morning.java9modules.service.repository")
@PropertySource("service.properties")
public class ServiceConfiguration {
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.lohika.morning.java9modules.service.domain;

//@Document(collection = "movies")

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

@Document(collection = "movies")
public class Movie {

// @Id
@Id
private String id;

private String title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@

import com.lohika.morning.java9modules.service.domain.Movie;

import org.springframework.data.mongodb.repository.MongoRepository;

import java.util.List;
import java.util.Optional;

public interface MovieRepository {

List<Movie> findAll();

Optional<Movie> findOne(String id);

Optional<Movie> findByTitle(String title);

List<Movie> findByGenre(String genre);

void deleteAll();
public interface MovieRepository extends MongoRepository<Movie, String> {
Optional<Movie> findByTitle(String title);

void save(Movie movie);
List<Movie> findByGenre(String genre);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.lohika.morning.java9modules.service.domain.Movie;
import com.lohika.morning.java9modules.service.repository.MovieRepository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import java.util.List;
import java.util.Optional;
import java.util.Random;
Expand All @@ -14,7 +16,7 @@
@Service
public class MovieService {

@Resource
@Autowired
private MovieRepository movieRepository;

public List<Movie> allMovies() {
Expand Down
7 changes: 5 additions & 2 deletions service/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
requires java.xml.ws.annotation;
requires spring.beans;
requires spring.context;
requires spring.data.mongodb;
requires spring.data.commons;
requires spring.boot.autoconfigure;
requires mongo.java.driver;

exports com.lohika.morning.java9modules.service.service to com.lohika.morning.java9modules.api;
exports com.lohika.morning.java9modules.service.domain to com.lohika.morning.java9modules.api;
exports com.lohika.morning.java9modules.service.configuration to com.lohika.morning.java9modules.api;

opens com.lohika.morning.java9modules.service.service;
opens com.lohika.morning.java9modules.service.configuration;
opens com.lohika.morning.java9modules.service.repository;
}
}