GET request is not answered correctly by the backend

5

The project is an Angular 6 front end, which connects to a Java back-end for communication with a SQL Server BD.

The server that receives the file .war , containing the back as the front, is Tomcat 8.5.32.

The structure for logging in follows four files:

  • The AuthController class, which officializes the login itself.

    @RestController
    @RequestMapping(value = "/api")
    public class AuthController {
    
    public static final Logger logger = LoggerFactory.getLogger(AuthController.class);
    
    @CrossOrigin
    @RequestMapping("/auth")
    public Principal user(Principal principal) {
        logger.info("usuário logado " + principal);
        return principal;
      }
    }
    
  • The LoginRepository interface, for querying in BD

    @Transactional
    public interface LoginRepository  extends JpaRepository<Login, Long>{
        Login findOneByUsername(String username);
    }
    
  • The class
  • UserService, which queries BD
  • @Service
    public class UserService {
      @Autowired
      LoginRepository userRepository;
    
      public Login save(Login user) {
         return userRepository.saveAndFlush(user);
      }
    
      public Login update(Login user) {
         return userRepository.save(user);
      }
    
      public Login find(String userName) {
         return userRepository.findOneByUsername(userName);
      }
    
      public Login find(Long id) {
         return userRepository.findOne(id);
      }
    
    }
    
  • And a second class service UserDetailsServiceImpl

    @Service
    public class UserDetailsServiceImpl implements UserDetailsService {
    
    @Autowired
    UserService userService;
    
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        Login user = userService.find(username);
        return user;
      }
    
    }
    
  • When sending a GET request to the endpoint /api/auth in the development environment, with the server running in the spring-boot, the login follows without problems, receiving the main object and then logging in.

    When I move to the format war with the appropriate adaptations, tests I have done show that the requests for the other tables follow without problem, except Login, which accesses the database and searches for the credential, but does not returns the Main object, but a 404 error.

    EDIT

    Excerpts from pom.xml

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <start-class>br.com.tradeturismo.ServletInitialzer</start-class>
        <maven.build.timestamp.format>ddMMyyyyHHmmss</maven.build.timestamp.format>
        <angular.project.location>portal</angular.project.location>
        <angular.project.nodeinstallation>node_installation</angular.project.nodeinstallation>
    </properties>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>1.6</version>
                <configuration>
                    <workingDirectory>${angular.project.location}</workingDirectory>
                    <installDirectory>${angular.project.nodeinstallation}</installDirectory>
                </configuration>
                <executions>
                    <execution>
                        <id>install node and npm</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                        <configuration>
                            <nodeVersion>v10.6.0</nodeVersion>
                            <npmVersion>6.1.0</npmVersion>
                        </configuration>
                    </execution>
    
                    <execution>
                        <id>npm install</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>install</arguments>
                        </configuration>
                    </execution>
    
                    <execution>
                        <id>npm build</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>run build</arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>default-copy-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <overwrite>false</overwrite>
                            <outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.basedir}/${angular.project.location}/dist</directory>
                                    <includes>
                                        <include>**/*.*</include>
                                    </includes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    
        
    asked by anonymous 17.08.2018 / 18:19

    2 answers

    1

    I finally managed to unravel the mystery.

    I had to change the value of the annotation @RequestMapping to <nome-do-projeto>-<versão> .

    For example, if your project calls "eneias" and its version is "1.0.0", the annotation should look like this:

    @RequestMapping(value = "/eneias-1.0.0")
    

    This is just for the first note, which is next to the class declaration. The second is unchanged.

        
    03.09.2018 / 18:29
    -1

    Are you considering the context of the application to make the call? by default is the name of your [name] .war file

    It would have to be something like this: link

        
    23.08.2018 / 23:22