Cannot load GraphHopper config via Java import (graphhopper-core Maven dependency) with prebuilt map cache and custom profiles

Cannot load GraphHopper config via Java(Spring Boot) import (graphhopper-core 10.0 Maven dependency) with prebuilt map cache and custom profiles

Hi everyone,

I’m trying to use GraphHopper in a Java Spring Boot application (using the graphhopper-core Maven dependency) and load a prebuilt map cache that includes custom profiles.

However, when the app starts, it fails to initialize GraphHopper with the following error:

Profiles do not match:
Graphhopper config: car|1003522894, custom_small_truck|1355125107, custom_truck|1977020159
Graph: car|-1868831333, custom_small_truck|1747821466, custom_truck|1246995638
Change configuration to match the graph or delete /graph-cache/

Error creating bean with name ‘hopper’ defined in class path resource [GraphHopperConf.class]:
Failed to instantiate [com.graphhopper.GraphHopper]: Factory method ‘hopper’ threw exception with message: Profiles do not match

Here’s what I’m doing:

  • I import the map cache that was already built with GraphHopper.importOrLoad.

  • When loading, I get the above mismatch between profile hashes.

My question is:
Why do these profile hashes not match when the configuration is the same?
Where is the mistake?)
Is there a proper way to load a prebuilt graph-cache with custom profiles from cache or i need to load profiles programmatically?
Or there are any better standard approaches?
I wanted to run graphhopper-core using the same config.yml and profiles.json from server

Any advice or example configuration would be really appreciated!

Thanks in advance.

Congiuration file is:


@Slf4j
@Configuration
public class GraphHopperConf2 {

    @Value("${graphhopper.cachePath}")
    private String cachePath;
    @Value("${graphhopper.profilePath}")
    private String profilePath;
    @Value("${graphhopper.configPath}")
    private String configPath;

    @Bean(destroyMethod = "close")
    public GraphHopper hopper() throws IOException {
        Path cfgFile = Path.of(configPath).toAbsolutePath().normalize();
        ObjectMapper yaml = new ObjectMapper(new YAMLFactory());
        //read config YAML asad Map
        Map<String, Object> root = yaml.readValue(cfgFile.toFile(), Map.class);
        Map<String, Object> gh = (Map<String, Object>) root.getOrDefault("graphhopper", root);

        // important key for GH 10: import.osm.ignored_highways
        if (!gh.containsKey("import.osm.ignored_highways")) {
            gh.put("import.osm.ignored_highways", "footway,cycleway,path,pedestrian,steps");
            LOG.warn("Added missing 'import.osm.ignored_highways' to config (using default)");
        }

        if (cachePath != null && !cachePath.isBlank()) {
            gh.put("graph.location", cachePath);
        }
        if (profilePath != null && !profilePath.isBlank()) {
            gh.put("custom_models.directory", profilePath);
        }

        // build GraphHopperConfig from map
        GraphHopperConfig ghCfg = new GraphHopperConfig();
        for (Map.Entry<String, Object> e : gh.entrySet()) {
            ghCfg.putObject(e.getKey(), e.getValue());
            System.out.println("key=" + e.getKey() + ", val=" + e.getValue());
        }

        // init + load (if cache is present — load(), else import())
        GraphHopper hopper = new GraphHopper().init(ghCfg);

        hopper.importOrLoad(); // load existing graph-cache
        return hopper;
    }
}