Skip to content

Commit

Permalink
1. Added main project documentation.
Browse files Browse the repository at this point in the history
2. Updated unit tests.
  • Loading branch information
conor10 committed Feb 19, 2017
1 parent 57f6c4d commit cc46f6a
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 9 deletions.
66 changes: 62 additions & 4 deletions README.md
@@ -1,15 +1,73 @@
# web3j Spring Boot Starter

Integrate web3j into your Spring Boot applications.
Integrate web3j into your Spring Boot applications via Spring's dependency injection.

Groovy:

```groovy
## Getting started

```
A sample application is available [here](https://github.com/web3j/examples/tree/master/spring-boot)

To use, create a new [Spring Boot Application](https://spring.io/guides/gs/spring-boot/), and
include the following dependencies:

Maven:

```xml
<dependency>
<groupId>org.web3j</groupId>
<artifactId>web3j-spring-boot-starter</artifactId>
<version>1.0.0</version>
</dependency>
```

Gradle:

```groovy
compile ('org.web3j:web3j-spring-boot-starter:1.0.0')
```

Now Spring can inject web3j instances for you where ever you need them:

```java
@Autowired
private Web3j web3j;
```

No additional configuration is required if you want to connect via HTTP to the default URL
http://localhost:8545.

Otherwise simply add the address of the endpoint in your application properties:

```properties
# An infura endpoint
web3j.client-address = https://morden.infura.io/

# Or, an IPC endpoing
web3j.client-address = /path/to/file.ipc
```


## Admin clients

If you wish to make use of the
[Parity](https://github.com/ethcore/parity/wiki/JSONRPC-personal-module) or
[Geth](https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal) personal modules
to manage accounts, enable the admin client:

```properties
web3j.admin-client = true
```

Then Spring can inject admin clients:

```java
@Autowired
private Parity parity;
```

**Note**: This is not required for transacting with web3j.


## Further information

For further information on web3j, please refer to the [web3j home page](https://web3j.io).
4 changes: 3 additions & 1 deletion settings.gradle
@@ -1 +1,3 @@
rootProject.name = 'spring-boot-starter'
// This should not be shortened
// See http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-auto-configuration.html#boot-features-custom-starter-naming
rootProject.name = 'web3j-spring-boot-starter'
Expand Up @@ -24,6 +24,7 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;


public class Web3jAutoConfigurationTest {
Expand Down Expand Up @@ -51,7 +52,7 @@ public void testHttpClient() throws Exception {
@Test
public void testInfuraHttpClient() throws Exception {
verifyHttpConnection(
"https://infura.io:12345", InfuraHttpService.class);
"https://infura.io/", InfuraHttpService.class);
}

@Test
Expand All @@ -77,13 +78,23 @@ public void testWindowsIpcClient() throws IOException {
@Test
public void testAdminClient() throws Exception {
load(EmptyConfiguration.class, "web3j.client-address=", "web3j.admin-client=true");

this.context.getBean(Parity.class);
try {
this.context.getBean(Web3j.class);
fail();
} catch (NoSuchBeanDefinitionException e) { }
}

@Test(expected = NoSuchBeanDefinitionException.class)
@Test
public void testNoAdminClient() throws Exception {
load(EmptyConfiguration.class, "web3j.client-address=", "web3j.admin-client=false");
this.context.getBean(Parity.class);
load(EmptyConfiguration.class, "web3j.client-address=");

this.context.getBean(Web3j.class);
try {
this.context.getBean(Parity.class);
fail();
} catch (NoSuchBeanDefinitionException e) { }
}

private void verifyHttpConnection(
Expand Down

0 comments on commit cc46f6a

Please sign in to comment.