I cannot use spring boot application on AWS EC2

Basically i have a running application on localhost, when i try to run my application on Aws ec2 , it gives me errors and i cannot understand why. I uploaded the full error file but here is what is i think causing the issue:
40 Replies
JavaBot
JavaBot2y ago
This post has been reserved for your question.
Hey @Ed! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Ed
EdOP2y ago
1-
onfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'networksController' defined in URL [jar:file:/home/ec2-user/spring-boot-aws.jar!/BOOT-INF/classes!/com/javatechie/aws/api/controllers/NetworksController.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'geoServiceImpl' defined in URL [jar:file:/home/ec2-user/spring-boot-aws.jar!/BOOT-INF/classes!/com/javatechie/aws/api/services/GeoService/GeoServiceImpl.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate
onfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'networksController' defined in URL [jar:file:/home/ec2-user/spring-boot-aws.jar!/BOOT-INF/classes!/com/javatechie/aws/api/controllers/NetworksController.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'geoServiceImpl' defined in URL [jar:file:/home/ec2-user/spring-boot-aws.jar!/BOOT-INF/classes!/com/javatechie/aws/api/services/GeoService/GeoServiceImpl.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate
2-
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'networksController' defined in URL [jar:file:/home/ec2-user/spring-boot-aws.jar!/BOOT-INF/classes!/com/javatechie/aws/api/controllers/NetworksController.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'geoServiceImpl' defined in URL [jar:file:/home/ec2-user/spring-boot-aws.jar!/BOOT-INF/classes!/com/javatechie/aws/api/services/GeoService/GeoServiceImpl.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.javatechie.aws.api.services.GeoService.GeoServiceImpl]: Constructor threw exception; nested exception is java.io.FileNotFoundException: class path resource [geo-lite.mmdb] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/home/ec2-user/spring-boot-aws.jar!/BOOT-INF/classes!/geo-lite.mmdb
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'networksController' defined in URL [jar:file:/home/ec2-user/spring-boot-aws.jar!/BOOT-INF/classes!/com/javatechie/aws/api/controllers/NetworksController.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'geoServiceImpl' defined in URL [jar:file:/home/ec2-user/spring-boot-aws.jar!/BOOT-INF/classes!/com/javatechie/aws/api/services/GeoService/GeoServiceImpl.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.javatechie.aws.api.services.GeoService.GeoServiceImpl]: Constructor threw exception; nested exception is java.io.FileNotFoundException: class path resource [geo-lite.mmdb] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/home/ec2-user/spring-boot-aws.jar!/BOOT-INF/classes!/geo-lite.mmdb
my networkcontroller class:
@RestController
@RequestMapping("/network")
public class NetworksController {
private final HttpServletRequest request;
private final GeoService geoService;
private String buffer;

@Autowired
public NetworksController(HttpServletRequest request, GeoService geoService) {
this.request = request;
this.geoService = geoService;

this.buffer = "x";
for (int i = 0; i < 23; i++) {
this.buffer += this.buffer;
}
}
...
@RestController
@RequestMapping("/network")
public class NetworksController {
private final HttpServletRequest request;
private final GeoService geoService;
private String buffer;

@Autowired
public NetworksController(HttpServletRequest request, GeoService geoService) {
this.request = request;
this.geoService = geoService;

this.buffer = "x";
for (int i = 0; i < 23; i++) {
this.buffer += this.buffer;
}
}
...
my GeoserviceImpl:
@Service
public class GeoServiceImpl implements GeoService {
private final DatabaseReader databaseReader;

final ResourceLoader resourceLoader;

@Autowired
public GeoServiceImpl(ResourceLoader resourceLoader) throws IOException {
String dbLocation = "geo-lite.mmdb";

Resource res = resourceLoader.getResource("classpath:" + dbLocation);
File f = new File(res.getFile().toURI());

databaseReader = new DatabaseReader.Builder(f).build();
this.resourceLoader = resourceLoader;
}
@Service
public class GeoServiceImpl implements GeoService {
private final DatabaseReader databaseReader;

final ResourceLoader resourceLoader;

@Autowired
public GeoServiceImpl(ResourceLoader resourceLoader) throws IOException {
String dbLocation = "geo-lite.mmdb";

Resource res = resourceLoader.getResource("classpath:" + dbLocation);
File f = new File(res.getFile().toURI());

databaseReader = new DatabaseReader.Builder(f).build();
this.resourceLoader = resourceLoader;
}
my code is functioning 100% offline but not online
Crain
Crain2y ago
Are you deploying this as a Jar?
Ed
EdOP2y ago
yeah
Crain
Crain2y ago
Does the Jar work locally
Ed
EdOP2y ago
i haven't tested 1 sec no actually no but it works from inside intellije
Crain
Crain2y ago
IntelliJ != Jar Welcome to learning that the hard way What is in geo-lite.mmdb?
Ed
EdOP2y ago
i have no idea, i am coding with a friend, we are doing backend for a speedtesting website he is using it for finding geo location of the user
Crain
Crain2y ago
If it is just Static Data, you could encode that into the Application.
Ed
EdOP2y ago
i think it is i couldn't even read it
Crain
Crain2y ago
Otherwise you're doing access a little wrong
Ed
EdOP2y ago
No description
Ed
EdOP2y ago
its been 3 hours i am trying to figure out why aws is not working, i tried running the server as .war on tomcat , then jar but nothing seems to work
Crain
Crain2y ago
Remove the classpath:, bundle to a Jar, try again locally We're not in the classpath, we're in the Resources Directory.
Ed
EdOP2y ago
i couldn't understand
Crain
Crain2y ago
@Service
public class GeoServiceImpl implements GeoService {
private final DatabaseReader databaseReader;

final ResourceLoader resourceLoader;

//Shouldn't need `@Autowired`
public GeoServiceImpl(ResourceLoader resourceLoader) throws IOException {
String dbLocation = "geo-lite.mmdb";

Resource res = resourceLoader.getResource(dbLocation); // Removed classpath:
File f = new File(res.getFile().toURI());

databaseReader = new DatabaseReader.Builder(f).build();
this.resourceLoader = resourceLoader;
}
@Service
public class GeoServiceImpl implements GeoService {
private final DatabaseReader databaseReader;

final ResourceLoader resourceLoader;

//Shouldn't need `@Autowired`
public GeoServiceImpl(ResourceLoader resourceLoader) throws IOException {
String dbLocation = "geo-lite.mmdb";

Resource res = resourceLoader.getResource(dbLocation); // Removed classpath:
File f = new File(res.getFile().toURI());

databaseReader = new DatabaseReader.Builder(f).build();
this.resourceLoader = resourceLoader;
}
Ed
EdOP2y ago
Ed
EdOP2y ago
its still not working: here is the highlights of the issue:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'networksController' defined in URL [jar:file:/C:/Users/Ed/Desktop/eaaasy/speed-test/server/target/server-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/com/example/server/controllers/NetworksController.class]: Unsatisfied dependency expressed through constructor parameter 1: Error creating bean with name 'geoServiceImpl' defined in URL [jar:file:/C:/Users/Ed/Desktop/eaaasy/speed-test/server/target/server-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/com/example/server/services/GeoService/GeoServiceImpl.class]: Failed to instantiate [com.example.server.services.GeoService.GeoServiceImpl]: Constructor threw exception
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'networksController' defined in URL [jar:file:/C:/Users/Ed/Desktop/eaaasy/speed-test/server/target/server-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/com/example/server/controllers/NetworksController.class]: Unsatisfied dependency expressed through constructor parameter 1: Error creating bean with name 'geoServiceImpl' defined in URL [jar:file:/C:/Users/Ed/Desktop/eaaasy/speed-test/server/target/server-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/com/example/server/services/GeoService/GeoServiceImpl.class]: Failed to instantiate [com.example.server.services.GeoService.GeoServiceImpl]: Constructor threw exception
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'networksController' defined in URL [jar:file:/C:/Users/Ed/Desktop/eaaasy/speed-test/server/target/server-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/com/example/server/controllers/NetworksController.class]: Unsatisfied dependency expressed through constructor parameter 1: Error creating bean with name 'geoServiceImpl' defined in URL [jar:file:/C:/Users/Ed/Desktop/eaaasy/speed-test/server/target/server-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/com/example/server/services/GeoService/GeoServiceImpl.class]: Failed to instantiate [com.example.server.services.GeoService.GeoServiceImpl]: Constructor threw exception
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'networksController' defined in URL [jar:file:/C:/Users/Ed/Desktop/eaaasy/speed-test/server/target/server-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/com/example/server/controllers/NetworksController.class]: Unsatisfied dependency expressed through constructor parameter 1: Error creating bean with name 'geoServiceImpl' defined in URL [jar:file:/C:/Users/Ed/Desktop/eaaasy/speed-test/server/target/server-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/com/example/server/services/GeoService/GeoServiceImpl.class]: Failed to instantiate [com.example.server.services.GeoService.GeoServiceImpl]: Constructor threw exception
(The system cannot find the file specified) should my string be something like this:
String dbLocation = "/resources/geo-lite.mmdb";
String dbLocation = "/resources/geo-lite.mmdb";
Crain
Crain2y ago
Maybe? Been a while since I did this I just know we're not on the classpath
Ed
EdOP2y ago
it didnt work i fixed it!!!!
Crain
Crain2y ago
What was the fix?
Ed
EdOP2y ago
@Service
public class GeoServiceImpl implements GeoService {
private final DatabaseReader databaseReader;

final ResourceLoader resourceLoader;

@Autowired
public GeoServiceImpl(ResourceLoader resourceLoader) throws IOException {
String dbLocation = "geo-lite.mmdb";

Resource resource = resourceLoader.getResource("classpath:" + dbLocation);
InputStream inputStream = resource.getInputStream();

databaseReader = new DatabaseReader.Builder(inputStream).build();
this.resourceLoader = resourceLoader;
}
@Service
public class GeoServiceImpl implements GeoService {
private final DatabaseReader databaseReader;

final ResourceLoader resourceLoader;

@Autowired
public GeoServiceImpl(ResourceLoader resourceLoader) throws IOException {
String dbLocation = "geo-lite.mmdb";

Resource resource = resourceLoader.getResource("classpath:" + dbLocation);
InputStream inputStream = resource.getInputStream();

databaseReader = new DatabaseReader.Builder(inputStream).build();
this.resourceLoader = resourceLoader;
}
jar doesnt access file like normal device does must be through inputstream
Crain
Crain2y ago
It's really weird depending on the Class Loader.
Ed
EdOP2y ago
now it runs in windows i hope it runs on aws
Crain
Crain2y ago
If the Jar ran, it'll run
Ed
EdOP2y ago
i hope i really hope i am 4 hours past my bed time from this error IT DIDNT RUN fml
Crain
Crain2y ago
did the jar run locally?
Ed
EdOP2y ago
yeah
Ed
EdOP2y ago
Ed
EdOP2y ago
sorry i uploaded a lot i think
Crain
Crain2y ago
how big is that file?
Ed
EdOP2y ago
51mb jar is 54 mb, the geo thing is 69 mbs
Crain
Crain2y ago
How much RAM is in your EC2 instead? instance* Since you're running out of Heap
Ed
EdOP2y ago
i might have fixed it with this java -Xmx6g myprogram it should be 30 i believe ITS FUCKING WORKING 😄
Crain
Crain2y ago
32 GB?
Ed
EdOP2y ago
beautiful error
No description
Ed
EdOP2y ago
i think so yeah
Crain
Crain2y ago
Well, good job
Ed
EdOP2y ago
they dont mention actually but i think it was 32 tyty i appreciate your help man Its time for me to go to bed good night friend
JavaBot
JavaBot2y ago
Post Closed
This post has been closed by <@351059014341099521>.

Did you find this page helpful?