title: Symfony 4 - The autoloader expected class […] to be defined in file
body: <p>I'm trying to add an old Bundle that I have built on <strong>Symfony 3.*</strong> to <strong>Symfony 4</strong> but I get this error:<br></p>
  
  <blockquote>
    <p>The autoloader expected class
    "App\SBC\TiersBundle\Controller\ChantierController" to be defined in
    file
    "/Applications/MAMP/htdocs/Projects/HelloSymfony4/vendor/composer/../../src/SBC/TiersBundle/Controller/ChantierController.php".
    The file was found but the class was not in it, the class name or
    namespace probably has a typo in
    /Applications/MAMP/htdocs/Projects/HelloSymfony4/config/services.yaml
    (which is loaded in resource
    "/Applications/MAMP/htdocs/Projects/HelloSymfony4/config/services.yaml").</p>
  </blockquote>
  
  <p>It seems like the framework did not recognise the namespace of the bundle so I did these steps:<br>
  In <code>config/bundle.php</code> I added the third line:<br></p>
  
  <pre><code>return [
      Symfony\Bundle\FrameworkBundle\FrameworkBundle::class =&gt; ['all' =&gt; true],
      Symfony\Bundle\TwigBundle\TwigBundle::class =&gt; ['all' =&gt; true],
      \SBC\TiersBundle\TiersBundle::class =&gt; ['all' =&gt; true], // this one
      Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class =&gt; ['dev' =&gt; true, 'test' =&gt; true],
  ];
  </code></pre>
  
  <p>And in <code>composer.json</code> I added the first line in <code>autoload</code> section:<br></p>
  
  <pre><code>"autoload": {
          "psr-4": {
              "SBC\\": "src/SBC/",
              "App\\": "src/"
  
          }
      },
  </code></pre>
  
  <p>Because the namespace of my Bundle starts with <code>SBC\</code>, and I have launched <code>composer dump-autoload</code> in the console.<br></p>
  
  <pre><code>&lt;?php
  
  namespace SBC\TiersBundle;
  
  use Symfony\Component\HttpKernel\Bundle\Bundle;
  
  class TiersBundle extends Bundle
  {
  }
  </code></pre>
  
  <p><strong>ChantierController.php</strong>:<br></p>
  
  <pre><code>namespace SBC\TiersBundle\Controller;
  
  use SBC\TiersBundle\Entity\Chantier;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Symfony\Component\HttpFoundation\JsonResponse;
  use Symfony\Component\HttpFoundation\Request;
  
  
  class ChantierController extends Controller
  {
  ...
  }
  </code></pre>
  
  <p>And this is my Bundle under /src:<br>
  <a href="https://i.stack.imgur.com/eKSzJ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/eKSzJ.png" alt="enter image description here"></a></p>
  
  <p>Unfortunately still facing the same error, how can I fix it and thanks in advance.</p>
  
  <p><strong>UPDATE</strong>: <code>config/services.yaml</code>:<br></p>
  
  <pre><code># Put parameters here that don't need to change on each machine where the app is deployed
  # https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
  parameters:
  
  services:
      # default configuration for services in *this* file
      _defaults:
          autowire: true      # Automatically injects dependencies in your services.
          autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
          public: false       # Allows optimizing the container by removing unused services; this also means
                              # fetching services directly from the container via $container-&gt;get() won't work.
                              # The best practice is to be explicit about your dependencies anyway.
  
      # makes classes in src/ available to be used as services
      # this creates a service per class whose id is the fully-qualified class name
      SBC\:
          resource: '../src/SBC/*'
          exclude: '../src/SBC/TiersBundle/{Entity,Migrations,Tests}'
  
      SBC\TiersBundle\Controller\:
          resource: '../src/SBC/TiersBundle/Controller'
          tags: ['controller.service_arguments']
  
      App\:
          resource: '../src/*'
          exclude: '../src/{Entity,Migrations,Tests}'
  
      # controllers are imported separately to make sure services can be injected
      # as action arguments even if you don't extend any base controller class
      App\Controller\:
          resource: '../src/Controller'
          tags: ['controller.service_arguments']
  
      # add more service definitions when explicit configuration is needed
      # please note that last definitions always *replace* previous ones
  </code></pre>