我使用 Intellij IDE 创建了一个 Java Spring 和 AngularJS 应用程序。我在 intellij 中创建了一个 war (Web Application:Exploded) 文件。我把这个war文件放在Tomcat webapps目录中,AngularJS代码部署得很好,我可以在浏览器中打开它。当我尝试使用 REST 调用调用我的服务器代码时,我得到了 404 not found 错误,我可以看到 tomcat 目录中没有 java 文件。我复制了java文件,但仍然没有乐趣。我是部署 Web 应用程序的新手。
如果有人可以帮助我如何让 angularJS 文件正确调用我的 java ,我将不胜感激。
谢谢你。
弹簧模块.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.services.impl"/>
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- Creating TransactionManager Bean, since JDBC we are creating of type
DataSourceTransactionManager -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="getUserRepo" class="com.Repo.impl.UserRepoImpl">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="dataManipulationRepo" class="com.Repo.impl.DataManipulationRepoImpl">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://127.0.0.1/xx"/>
<property name="username" value="root"/>
<property name="password" value="xx"/>
</bean>
</beans>
mvc-调度程序-servlet:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.controller"/>
<mvc:resources mapping="/app/**" location="/app/build/"/>
<mvc:annotation-driven/>
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
项目结构
WEB-INF
|_ jsp folder
|_ lib folder
|_ web.xml
|_ mvc-dispatcher-servlet.xml
|_ classes folder
|_ com folder (controller, model, services, resources, Repo folders with .class files within each)
|_ Spring-Module.xml
app
|_ html files
解决方案
我得到它的工作!我的 REST 调用使用大写字母。我在调用中使用大写的项目名称,然后在导致问题的浏览器 URL 中使用小写。使用 chrome Postman 应用程序也很有帮助。