-
Notifications
You must be signed in to change notification settings - Fork 141
Upgrade Java runner with better support #383
Comments
Can we have Spring (core) instead of Spring boot? sample Spring hello world:
you can test it in the console like a normal java program ( without other spring libraries it mostly does Dependency Injection ) . sample Spring boot hello world:
you can test it from your browser and check that the server that says hello world has been condigured at localhost:8080. |
I'm not a Java/Spring guy. Is spring core just something that I need to include as its own dependency within Gradle? It looks like without Spring Boot we would need to be able to define a This currently works: package hello;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class HttpRequestTest {
@LocalServerPort
private int port;
@Autowired
private TestRestTemplate restTemplate;
@Test
public void greetingShouldReturnDefaultMessage() throws Exception {
assertThat(this.restTemplate.getForObject("http://localhost:" + port + "/",
String.class)).contains("Hello World");
}
} |
Yes.. but you are creating a rest webservice with an embedded webserver for every run at a randomly chosen port. Annotation configuration is prefered over XML configuration. You can use So lets say we have our context config as follows:
At services we can have the class to be injected (let's say it's the equivalent for preloaded code if you use with a normal file or the test target if no as in this case)
And out test code for the service could be something like:
The magic of Spring is that you could easily integrate any service in common code as follows:
Hope this code caan be useful to you. |
Thanks, that is very helpful. So can this be handled simply by providing |
Actually it looks like core and context should already be loaded, via Spring boot... so it seems like you can use boot or not use boot - both are supported. Is this correct? |
As you may see both projects are separated (even if spring boot uses internally the spring framework) but is more like a crystal on rails than a ruby on rails. Certainly it configures all to ease the learning curve, but there are some subtle differences with spring framework applications i.e. with spring-webmvc, and the most important for me is that testing is performed very differently. |
I'm trying to understand the action item here. Both are supported as of now AFAIKT. Simply include "spring" as a reference and use whichever you prefer. Have you seen the spring PR that I recently merged? |
Closing because the original issue is no longer relevant. |
Java needs a number of improvements. Before we can embark on many of them, we initially will need to move Java off of the JVM-runner so that we can support it better.
The text was updated successfully, but these errors were encountered: