Skip to content

Commit 7f0229e

Browse files
committed
feat(spring-boot-starter-adk): Add Spring Boot Starter support and update the project structure
1 parent f9143c2 commit 7f0229e

File tree

6 files changed

+166
-1
lines changed

6 files changed

+166
-1
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.google.adk</groupId>
9+
<artifactId>google-adk-parent</artifactId>
10+
<version>0.2.1-SNAPSHOT</version><!-- {x-version-update:google-adk:current} -->
11+
<relativePath>../../pom.xml</relativePath>
12+
</parent>
13+
14+
<artifactId>spring-boot-starter-adk</artifactId>
15+
<name>Agent Development Kit - Spring Boot Starter</name>
16+
<description>Spring Boot Starter for the Agent Development Kit.</description>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>com.google.adk</groupId>
21+
<artifactId>google-adk</artifactId>
22+
<version>${project.version}</version>
23+
</dependency>
24+
<dependency>
25+
<groupId>com.google.adk</groupId>
26+
<artifactId>google-adk-dev</artifactId>
27+
<version>${project.version}</version>
28+
</dependency>
29+
30+
<!-- Test dependencies -->
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-test</artifactId>
34+
<scope>test</scope>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.mockito</groupId>
38+
<artifactId>mockito-core</artifactId>
39+
<scope>test</scope>
40+
</dependency>
41+
</dependencies>
42+
</project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.adk.starters.springboot;
17+
18+
import org.slf4j.Logger;
19+
import org.slf4j.LoggerFactory;
20+
import org.springframework.context.annotation.ComponentScan;
21+
import org.springframework.context.annotation.Configuration;
22+
23+
@Configuration
24+
@ComponentScan(
25+
basePackages = {"com.google.adk"},
26+
excludeFilters = {
27+
@ComponentScan.Filter(
28+
type = org.springframework.context.annotation.FilterType.ANNOTATION,
29+
value = org.springframework.boot.autoconfigure.SpringBootApplication.class)
30+
})
31+
public class AdkSpringbootAutoConfiguration {
32+
33+
private static final Logger logger =
34+
LoggerFactory.getLogger(AdkSpringbootAutoConfiguration.class);
35+
36+
public AdkSpringbootAutoConfiguration() {
37+
logger.info("AdkSpringbootAutoConfiguration initialized.");
38+
}
39+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com.google.adk.starters.springboot.AdkSpringbootAutoConfiguration
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.adk.starters.springboot;
18+
19+
import static org.junit.jupiter.api.Assertions.assertNotNull;
20+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
21+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
22+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
23+
24+
import com.google.adk.agents.BaseAgent;
25+
import com.google.adk.agents.LlmAgent;
26+
import com.google.adk.web.AdkWebServer;
27+
import com.google.adk.web.AgentStaticLoader;
28+
import org.junit.jupiter.api.Test;
29+
import org.springframework.beans.factory.annotation.Autowired;
30+
import org.springframework.boot.SpringApplication;
31+
import org.springframework.boot.autoconfigure.SpringBootApplication;
32+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
33+
import org.springframework.boot.test.context.SpringBootTest;
34+
import org.springframework.context.annotation.Bean;
35+
import org.springframework.context.annotation.Configuration;
36+
import org.springframework.test.web.servlet.MockMvc;
37+
38+
/**
39+
* Integration tests for the ADK Spring Boot Starter.
40+
*
41+
* <p>These tests use MockMvc to simulate HTTP requests and verify the expected responses from the
42+
* ADK API server, ensuring that the Spring Boot autoconfiguration works correctly.
43+
*/
44+
@SpringBootTest(properties = "adk.agents.loader=static")
45+
@AutoConfigureMockMvc
46+
public class AdkSpringbootStarterTest {
47+
48+
@Autowired private AgentStaticLoader agentStaticLoader;
49+
50+
@Autowired private MockMvc mockMvc;
51+
52+
@Test
53+
void testAgentStaticLoaderIsLoaded() throws Exception {
54+
assertNotNull(agentStaticLoader);
55+
mockMvc
56+
.perform(get("/list-apps"))
57+
.andExpect(status().isOk())
58+
.andExpect(content().json("[\"test_agent\"]"));
59+
}
60+
61+
@SpringBootApplication
62+
public static class TestApplication {
63+
public static void main(String[] args) {
64+
SpringApplication.run(TestApplication.class, args);
65+
}
66+
}
67+
68+
@Configuration
69+
public static class AppConfig {
70+
@Bean("agentLoader")
71+
public AgentStaticLoader agentStaticLoader() {
72+
BaseAgent testAgent =
73+
LlmAgent.builder()
74+
.name("test_agent")
75+
.model("gemini-2.0-flash-lite")
76+
.description("Test agent for demonstrating AgentStaticLoader")
77+
.instruction("You are a test agent.")
78+
.build();
79+
return new AgentStaticLoader(testAgent);
80+
}
81+
}
82+
}

dev/src/main/java/com/google/adk/web/AgentStaticLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* <p>This class is not a Spring component by itself - instances are created programmatically and
3838
* then registered as beans via factory methods.
3939
*/
40-
class AgentStaticLoader implements AgentLoader {
40+
public class AgentStaticLoader implements AgentLoader {
4141

4242
private final ImmutableMap<String, BaseAgent> agents;
4343

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<module>dev</module>
3232
<module>maven_plugin</module>
3333
<module>contrib/langchain4j</module>
34+
<module>contrib/spring-boot-starter-adk</module>
3435
<module>tutorials/city-time-weather</module>
3536
</modules>
3637

0 commit comments

Comments
 (0)