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 both the back and the front, is Tomcat 8.5.32.
The login execution structure follows four files:
The Authcontroller class, which makes the login itself official.
@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, to make queries in BD
@Transactional public interface LoginRepository extends JpaRepository<Login, Long>{ Login findOneByUsername(String username); }
The class-service Userservice, which performs queries in the 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 endpoint /api/auth
in development environment, with the server running in spring-boot, the login goes smoothly, receiving the Main object and then logging into the system.
When I step into the format war
with the appropriate adaptations, tests I did show that the requests to the other tables follow without problem, with the exception of Login, which accesses the database and searches for the credential, but does not return the Main object, but an error 404.
EDIT
Snippets of 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>
Hello! What returns then? An error?
– Dherik
If I’m not mistaken, he returns either a 404 or a 401
– mutlei
@Dherik edited the question with the back-end answer
– mutlei
As you gave a "Not Found Exception", you have the Tomcat log snippet to make it easier to identify what is not being found?
– ayowole agbedejobi
@ayowoleagbedejobi was not a java Exception, but an HTTP 404 error
– mutlei
you read in this tutorial, I think your problem is in port conflict that you are using and how to declare: https://www.devglan.com/spring-boot/spring-boot-angular-example
– Um Programador
@A programmer earlier today in my research I ended up finding just this tutorial. I’m trying to adapt it to my case at this time hehe
– mutlei
@mutlei, which adaptations were made to make the WAR deploy?
– Dherik
Changes in pom.xml. indicating the initial class of the project, plus settings to do the integration. I put the plugins of the answer to this question.
– mutlei
I added some details of pom.xml to the question
– mutlei